Skip to content
Snippets Groups Projects
Commit f3cce96c authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Added Theming

parent 0ecafb9c
Branches
Tags
No related merge requests found
Showing
with 730 additions and 183 deletions
......@@ -148,6 +148,8 @@ dependencies {
// UI Libs
compile 'com.bignerdranch.android:expandablerecyclerview:2.0.4'
compile 'com.fnp:material-preferences:0.1.4'
compile 'com.pavelsikun:material-seekbar-preference:0.12.1+'
compile(name:'library-release', ext:'aar')
compile('com.mikepenz:materialdrawer:5.0.0.b27-SNAPSHOT@aar') { transitive = true }
compile('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') { transitive = true }
......
......@@ -23,7 +23,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.kuschku.quasseldroid_ng">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
......@@ -63,17 +62,25 @@
<activity
android:name=".ui.setup.AccountSetupActivity"
android:label="Setup a new Account"
android:label="Account Setup"
android:launchMode="singleTask"
android:parentActivityName=".ui.setup.AccountSelectActivity"
android:theme="@style/SetupTheme" />
<activity
android:name=".ui.setup.AccountSelectActivity"
android:label="Select an Account"
android:label="Account Selection"
android:launchMode="singleTask"
android:parentActivityName=".ui.LoginActivity"
android:theme="@style/SetupTheme" />
<activity
android:name=".ui.settings.SettingsActivity"
android:label="Settings"
android:launchMode="singleTask"
android:parentActivityName=".ui.chat.MainActivity"
android:theme="@style/AppTheme.Light" />
</application>
</manifest>
......@@ -35,7 +35,7 @@ import de.kuschku.libquassel.events.GeneralErrorEvent;
import de.kuschku.libquassel.events.LoginRequireEvent;
import de.kuschku.libquassel.localtypes.backlogstorage.MemoryBacklogStorage;
import de.kuschku.libquassel.protocols.RemotePeer;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.settings.Settings;
import de.kuschku.util.CompatibilityUtils;
import de.kuschku.util.accounts.Account;
import de.kuschku.util.accounts.AccountManager;
......@@ -94,7 +94,7 @@ public class ClientBackgroundThread implements Runnable {
public void onEvent(LoginRequireEvent event) {
if (!event.failedLast) {
Account account = manager.account(settings.lastAccount.get());
Account account = manager.account(settings.preferenceLastAccount.get());
client().client.login(account.user, account.pass);
}
}
......
......@@ -27,8 +27,8 @@ import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import de.kuschku.quasseldroid_ng.ui.chat.MainActivity;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.chat.util.ServiceHelper;
import de.kuschku.quasseldroid_ng.ui.settings.Settings;
import de.kuschku.quasseldroid_ng.ui.setup.AccountSelectActivity;
import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
......@@ -57,16 +57,16 @@ public class LoginActivity extends AppCompatActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
context.settings().lastAccount.set(data.getBundleExtra("extra").getString("account"));
context.settings().preferenceLastAccount.set(data.getBundleExtra("extra").getString("account"));
checkReady();
firstStart = true;
} else if (context.settings().lastAccount.get().isEmpty()) {
} else if (context.settings().preferenceLastAccount.get().isEmpty()) {
finish();
}
}
private boolean checkReady() {
if (context.settings().lastAccount.get().isEmpty()) {
if (context.settings().preferenceLastAccount.get().isEmpty()) {
Intent intent = new Intent(this, AccountSelectActivity.class);
startActivityForResult(intent, 0);
firstStart = true;
......
......@@ -34,6 +34,7 @@ import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import de.kuschku.libquassel.client.Client;
import de.kuschku.libquassel.events.GeneralErrorEvent;
import de.kuschku.libquassel.localtypes.buffers.ChannelBuffer;
import de.kuschku.libquassel.syncables.types.interfaces.QIrcChannel;
......@@ -71,7 +72,10 @@ public class ChannelDetailActivity extends BoundActivity {
protected void onConnectToThread(@Nullable ClientBackgroundThread thread) {
super.onConnectToThread(thread);
ChannelBuffer buffer = (ChannelBuffer) context.client().bufferManager().buffer(this.buffer);
Client client = context.client();
if (client == null) return;
ChannelBuffer buffer = (ChannelBuffer) client.bufferManager().buffer(this.buffer);
if (buffer == null) return;
QIrcChannel channel = buffer.getChannel();
......@@ -112,10 +116,10 @@ public class ChannelDetailActivity extends BoundActivity {
TextView description = (TextView) v.findViewById(R.id.description);
TextView value = (TextView) v.findViewById(R.id.value);
String modeName = context.themeUtil().translations.chanModeToName(mode);
String modeName = context.themeUtil().chanModes.chanModeToName(mode);
name.setText(String.format("%s (+%s)", modeName, c));
String modeDescription = context.themeUtil().translations.chanModeToDescription(mode);
String modeDescription = context.themeUtil().chanModes.chanModeToDescription(mode);
description.setText(modeDescription);
String modeValue = channel.modeValue(c);
......
......@@ -70,6 +70,7 @@ import de.kuschku.quasseldroid_ng.ui.chat.drawer.BufferViewConfigAdapter;
import de.kuschku.quasseldroid_ng.ui.chat.fragment.ChatFragment;
import de.kuschku.quasseldroid_ng.ui.chat.fragment.LoadingFragment;
import de.kuschku.quasseldroid_ng.ui.chat.util.Status;
import de.kuschku.quasseldroid_ng.ui.settings.SettingsActivity;
import de.kuschku.util.accounts.Account;
import de.kuschku.util.accounts.AccountManager;
import de.kuschku.util.certificates.CertificateUtils;
......@@ -210,13 +211,16 @@ public class MainActivity extends BoundActivity {
case R.id.action_reauth:
reauth();
return true;
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void reauth() {
context.settings().lastAccount.set("");
context.settings().preferenceLastAccount.set("");
stopConnection();
finish();
}
......@@ -318,7 +322,7 @@ public class MainActivity extends BoundActivity {
protected void onConnectToThread(@Nullable ClientBackgroundThread thread) {
super.onConnectToThread(thread);
if (thread == null)
connectToServer(manager.account(context.settings().lastAccount.get()));
connectToServer(manager.account(context.settings().preferenceLastAccount.get()));
else {
if (context.client() != null && context.client().connectionStatus() == ConnectionChangeEvent.Status.CONNECTED) {
onConnected();
......@@ -434,7 +438,7 @@ public class MainActivity extends BoundActivity {
String username = usernameField.getText().toString();
String password = passwordField.getText().toString();
Account account = manager.account(context.settings().lastAccount.get());
Account account = manager.account(context.settings().preferenceLastAccount.get());
manager.update(account.withLoginData(username, password));
})
.cancelListener(dialog1 -> finish())
......
......@@ -99,7 +99,7 @@ public class ChatMessageRenderer {
@NonNull
private CharSequence formatNick(@NonNull String hostmask) {
return formatNick(hostmask, context.settings().fullHostmask.or(false));
return formatNick(hostmask, context.settings().preferenceHostmask.or(false));
}
@NonNull
......
......@@ -23,6 +23,7 @@ package de.kuschku.quasseldroid_ng.ui.chat.drawer;
import android.databinding.Observable;
import android.databinding.ObservableField;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
......@@ -74,7 +75,7 @@ public class BufferViewHolder extends ChildViewHolder {
context.provider().event.registerSticky(this);
background = new StateListDrawable();
background.addState(new int[]{android.R.attr.state_selected}, itemView.getResources().getDrawable(com.mikepenz.materialdrawer.R.color.material_drawer_selected));
background.addState(new int[]{android.R.attr.state_selected}, new ColorDrawable(context.themeUtil().res.colorSelected));
background.addState(new int[0], UIUtils.getSelectableBackground(itemView.getContext()));
}
......
......@@ -27,7 +27,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import de.kuschku.quasseldroid_ng.service.QuasselService;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.settings.Settings;
import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
import de.kuschku.quasseldroid_ng.ui.theme.AppTheme;
import de.kuschku.quasseldroid_ng.ui.theme.ThemeUtil;
......@@ -64,13 +64,14 @@ public class ServiceHelper {
context.startService(intent);
}
public static void initTheme(AppContext context, Activity activity) {
public static int initTheme(AppContext context, Activity activity) {
// Init SharedPreferences
Settings settings = new Settings(activity);
context.setSettings(settings);
// Load Theme from Preferences
AppTheme theme = AppTheme.themeFromString(settings.theme.get());
AppTheme theme = AppTheme.themeFromString(settings.preferenceTheme.get());
activity.setTheme(theme.themeId);
context.setThemeUtil(new ThemeUtil(activity, theme));
return theme.themeId;
}
}
......@@ -19,44 +19,50 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid_ng.ui.chat;
package de.kuschku.quasseldroid_ng.ui.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.preference.PreferenceManager;
import de.kuschku.util.backports.Objects;
import de.kuschku.quasseldroid_ng.ui.theme.PreferenceStrings;
import de.kuschku.util.preferences.BooleanPreference;
import de.kuschku.util.preferences.IntPreference;
import de.kuschku.util.preferences.StringPreference;
public class Settings {
public final StringPreference lastAccount;
public final StringPreference preferenceLastAccount;
public final IntPreference textSize;
public final StringPreference preferenceTheme;
public final BooleanPreference preferenceColors;
public final BooleanPreference preferenceBrackets;
public final BooleanPreference preferenceHostmask;
public final BooleanPreference preferenceLag;
public final IntPreference preferenceFontSize;
public final BooleanPreference mircColors;
public Settings(PreferenceStrings prefs, SharedPreferences pref) {
this.preferenceLastAccount = new StringPreference(pref, prefs.preferenceLastAccount, "");
public final BooleanPreference fullHostmask;
public final StringPreference theme;
public Settings(SharedPreferences pref) {
this.lastAccount = new StringPreference(pref, "lastAccount", "");
this.textSize = new IntPreference(pref, "textSize", 2);
this.mircColors = new BooleanPreference(pref, "mircColors", true);
this.fullHostmask = new BooleanPreference(pref, "fullHostmask", false);
this.theme = new StringPreference(pref, "theme", "QUASSEL_LIGHT");
this.preferenceTheme = new StringPreference(pref, prefs.preferenceTheme, "QUASSEL_LIGHT");
this.preferenceColors = new BooleanPreference(pref, prefs.preferenceColors, true);
this.preferenceBrackets = new BooleanPreference(pref, prefs.preferenceBrackets, false);
this.preferenceHostmask = new BooleanPreference(pref, prefs.preferenceHostmask, false);
this.preferenceLag = new BooleanPreference(pref, prefs.preferenceLag, false);
this.preferenceFontSize = new IntPreference(pref, prefs.preferenceFontSize, 14);
pref.registerOnSharedPreferenceChangeListener((preferences, key) -> {
if (Objects.equals(key, "lastAccount")) lastAccount.change();
if (Objects.equals(key, "textSize")) textSize.change();
if (Objects.equals(key, "mircColors")) mircColors.change();
if (Objects.equals(key, "fullHostmask")) fullHostmask.change();
if (Objects.equals(key, "theme")) theme.change();
if (prefs.preferenceLastAccount.equals(key)) preferenceLastAccount.change();
if (prefs.preferenceTheme.equals(key)) preferenceTheme.change();
if (prefs.preferenceColors.equals(key)) preferenceColors.change();
if (prefs.preferenceBrackets.equals(key)) preferenceBrackets.change();
if (prefs.preferenceHostmask.equals(key)) preferenceHostmask.change();
if (prefs.preferenceLag.equals(key)) preferenceLag.change();
if (prefs.preferenceFontSize.equals(key)) preferenceFontSize.change();
});
}
public Settings(Context ctx) {
this(ctx.getSharedPreferences("de.kuschku.quasseldroid_ng", 0));
this(new PreferenceStrings(ctx), PreferenceManager.getDefaultSharedPreferences(ctx));
}
}
/*
* QuasselDroid - Quassel client for Android
* Copyright (C) 2016 Janne Koschinski
* Copyright (C) 2016 Ken Børge Viktil
* Copyright (C) 2016 Magnus Fjell
* Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid_ng.ui.settings;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import butterknife.Bind;
import butterknife.ButterKnife;
import de.kuschku.quasseldroid_ng.R;
import de.kuschku.quasseldroid_ng.ui.chat.util.ServiceHelper;
import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
import de.kuschku.quasseldroid_ng.ui.theme.AppTheme;
public class SettingsActivity extends AppCompatActivity {
AppContext context = new AppContext();
@Bind(R.id.toolbar)
Toolbar toolbar;
int themeid;
@Override
public void onCreate(Bundle savedInstanceState) {
themeid = ServiceHelper.initTheme(context, this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setPreferenceFragment(new AppearanceFragment());
context.settings().preferenceTheme.addChangeListener(value -> restart());
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (themeid != AppTheme.resFromString(context.settings().preferenceTheme.get()))
restart();
}
public void restart() {
startActivity(getIntent());
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
public void setPreferenceFragment(PreferenceFragment preferenceFragment) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.content_host, preferenceFragment);
transaction.commit();
}
public static class AppearanceFragment extends PreferenceFragment {
AppContext context = new AppContext();
@Override
public void onCreate(Bundle savedInstanceState) {
ServiceHelper.initTheme(context, getActivity());
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_appearance);
}
}
}
......@@ -25,7 +25,7 @@ import android.support.annotation.NonNull;
import de.kuschku.libquassel.BusProvider;
import de.kuschku.libquassel.client.Client;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.settings.Settings;
import de.kuschku.util.irc.format.IrcFormatDeserializer;
import de.kuschku.util.irc.format.IrcFormatSerializer;
......
......@@ -32,6 +32,7 @@ public enum AppTheme {
QUASSEL_DARK(R.style.Quassel_Dark),
MATERIAL_DARK(R.style.Material_Dark),
MATERIAL_LIGHT(R.style.Material_Light),
SOLARIZED_LIGHT(R.style.Solarized_Light),
SOLARIZED_DARK(R.style.Solarized_Dark);
public final int themeId;
......@@ -54,6 +55,8 @@ public enum AppTheme {
return MATERIAL_LIGHT;
case "QUASSEL_DARK":
return QUASSEL_DARK;
case "SOLARIZED_LIGHT":
return SOLARIZED_LIGHT;
case "SOLARIZED_DARK":
return SOLARIZED_DARK;
......
/*
* QuasselDroid - Quassel client for Android
* Copyright (C) 2016 Janne Koschinski
* Copyright (C) 2016 Ken Børge Viktil
* Copyright (C) 2016 Magnus Fjell
* Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid_ng.ui.theme;
import android.content.Context;
import de.kuschku.quasseldroid_ng.R;
import de.kuschku.util.annotationbind.AutoBinder;
import de.kuschku.util.annotationbind.AutoString;
public class PreferenceStrings {
@AutoString(R.string.preference_last_account)
public String preferenceLastAccount;
@AutoString(R.string.preference_font_size)
public String preferenceFontSize;
@AutoString(R.string.preference_theme)
public String preferenceTheme;
@AutoString(R.string.preference_colors)
public String preferenceColors;
@AutoString(R.string.preference_brackets)
public String preferenceBrackets;
@AutoString(R.string.preference_hostmask)
public String preferenceHostmask;
@AutoString(R.string.preference_lag)
public String preferenceLag;
public PreferenceStrings(Context wrapper) {
try {
AutoBinder.bind(this, wrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
......@@ -44,10 +44,16 @@ import de.kuschku.util.ui.SpanFormatter;
public class ThemeUtil {
@NonNull
public final Colors res = new Colors();
@NonNull
public final FormatStrings translations = new FormatStrings();
@NonNull
public final ChanModeStrings chanModes = new ChanModeStrings();
@NonNull
public final DateTimeFormatHelper formatter;
@NonNull
public final StatusDrawables statusDrawables;
......@@ -68,6 +74,7 @@ public class ThemeUtil {
try {
AutoBinder.bind(res, wrapper);
AutoBinder.bind(translations, wrapper);
AutoBinder.bind(chanModes, wrapper);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
......@@ -125,79 +132,7 @@ public class ThemeUtil {
}
}
public static class FormatStrings {
@AutoString(R.string.usernameHostmask)
public String usernameHostmask;
@AutoString(R.string.messagePlain)
public String messagePlain;
@AutoString(R.string.messageJoin)
public String messageJoin;
@AutoString(R.string.messagePart)
public String messagePart;
@AutoString(R.string.messagePartExtra)
public String messagePartExtra;
@AutoString(R.string.messageQuit)
public String messageQuit;
@AutoString(R.string.messageQuitExtra)
public String messageQuitExtra;
@AutoString(R.string.messageKill)
public String messageKill;
@AutoString(R.string.messageKick)
public String messageKick;
@AutoString(R.string.messageKickExtra)
public String messageKickExtra;
@AutoString(R.string.messageMode)
public String messageMode;
@AutoString(R.string.messageNickSelf)
public String messageNickSelf;
@AutoString(R.string.messageNickOther)
public String messageNickOther;
@AutoString(R.string.messageDayChange)
public String messageDaychange;
@AutoString(R.string.messageAction)
public String messageAction;
@AutoString(R.string.labelStatusBuffer)
public String titleStatusBuffer;
@AutoString(R.string.warningCertificate)
public String warningCertificate;
@AutoString(R.string.statusConnecting)
public String statusConnecting;
@AutoString(R.string.statusHandshake)
public String statusHandshake;
@AutoString(R.string.statusInitData)
public String statusInitData;
@AutoString(R.string.statusBacklog)
public String statusBacklog;
@AutoString(R.string.statusConnected)
public String statusConnected;
@AutoString(R.string.statusDisconnected)
public String statusDisconnected;
@AutoString(R.string.statusWelcome)
public String statusWelcome;
public static class ChanModeStrings {
@AutoString(R.string.chanMode_RESTRICT_TOPIC_NAME)
public String chanMode_RESTRICT_TOPIC_NAME;
......@@ -434,88 +369,6 @@ public class ThemeUtil {
public String chanMode_FORWARD_DESCRIPTION;
@NonNull
public CharSequence formatUsername(@NonNull CharSequence nick, @NonNull CharSequence hostmask) {
return SpanFormatter.format(usernameHostmask, nick, hostmask);
}
@NonNull
public CharSequence formatJoin(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageJoin, user, channel);
}
@NonNull
public CharSequence formatPart(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messagePart, user, channel);
}
@NonNull
public CharSequence formatPart(@NonNull CharSequence user, @NonNull CharSequence channel, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatPart(user, channel);
return SpanFormatter.format(messagePartExtra, user, channel, reason);
}
@NonNull
public CharSequence formatQuit(@NonNull CharSequence user) {
return SpanFormatter.format(messageQuit, user);
}
@NonNull
public CharSequence formatQuit(@NonNull CharSequence user, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatQuit(user);
return SpanFormatter.format(messageQuitExtra, user, reason);
}
@NonNull
public CharSequence formatKill(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageKill, user, channel);
}
@NonNull
public CharSequence formatKick(@NonNull CharSequence user, @NonNull CharSequence kicked) {
return SpanFormatter.format(messageKick, user, kicked);
}
@NonNull
public CharSequence formatKick(@NonNull CharSequence user, @NonNull CharSequence kicked, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatKick(user, kicked);
return SpanFormatter.format(messageKickExtra, user, kicked, reason);
}
@NonNull
public CharSequence formatMode(@NonNull CharSequence mode, @NonNull CharSequence user) {
return SpanFormatter.format(messageMode, mode, user);
}
@NonNull
public CharSequence formatNick(@NonNull CharSequence newNick) {
return SpanFormatter.format(messageNickSelf, newNick);
}
@NonNull
public CharSequence formatNick(@NonNull CharSequence oldNick, @Nullable CharSequence newNick) {
if (newNick == null || newNick.length() == 0) return formatNick(oldNick);
return SpanFormatter.format(messageNickOther, oldNick, newNick);
}
@NonNull
public CharSequence formatDayChange(@NonNull CharSequence day) {
return SpanFormatter.format(messageDaychange, day);
}
@NonNull
public CharSequence formatAction(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageAction, user, channel);
}
@NonNull
public CharSequence formatPlain(@NonNull CharSequence nick, @NonNull CharSequence message) {
return SpanFormatter.format(messagePlain, nick, message);
}
public String chanModeToDescription(ChanMode mode) {
switch (mode) {
......@@ -686,6 +539,163 @@ public class ThemeUtil {
}
}
public static class FormatStrings {
@AutoString(R.string.usernameHostmask)
public String usernameHostmask;
@AutoString(R.string.messagePlain)
public String messagePlain;
@AutoString(R.string.messageJoin)
public String messageJoin;
@AutoString(R.string.messagePart)
public String messagePart;
@AutoString(R.string.messagePartExtra)
public String messagePartExtra;
@AutoString(R.string.messageQuit)
public String messageQuit;
@AutoString(R.string.messageQuitExtra)
public String messageQuitExtra;
@AutoString(R.string.messageKill)
public String messageKill;
@AutoString(R.string.messageKick)
public String messageKick;
@AutoString(R.string.messageKickExtra)
public String messageKickExtra;
@AutoString(R.string.messageMode)
public String messageMode;
@AutoString(R.string.messageNickSelf)
public String messageNickSelf;
@AutoString(R.string.messageNickOther)
public String messageNickOther;
@AutoString(R.string.messageDayChange)
public String messageDaychange;
@AutoString(R.string.messageAction)
public String messageAction;
@AutoString(R.string.labelStatusBuffer)
public String titleStatusBuffer;
@AutoString(R.string.warningCertificate)
public String warningCertificate;
@AutoString(R.string.statusConnecting)
public String statusConnecting;
@AutoString(R.string.statusHandshake)
public String statusHandshake;
@AutoString(R.string.statusInitData)
public String statusInitData;
@AutoString(R.string.statusBacklog)
public String statusBacklog;
@AutoString(R.string.statusConnected)
public String statusConnected;
@AutoString(R.string.statusDisconnected)
public String statusDisconnected;
@AutoString(R.string.statusWelcome)
public String statusWelcome;
@NonNull
public CharSequence formatUsername(@NonNull CharSequence nick, @NonNull CharSequence hostmask) {
return SpanFormatter.format(usernameHostmask, nick, hostmask);
}
@NonNull
public CharSequence formatJoin(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageJoin, user, channel);
}
@NonNull
public CharSequence formatPart(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messagePart, user, channel);
}
@NonNull
public CharSequence formatPart(@NonNull CharSequence user, @NonNull CharSequence channel, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatPart(user, channel);
return SpanFormatter.format(messagePartExtra, user, channel, reason);
}
@NonNull
public CharSequence formatQuit(@NonNull CharSequence user) {
return SpanFormatter.format(messageQuit, user);
}
@NonNull
public CharSequence formatQuit(@NonNull CharSequence user, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatQuit(user);
return SpanFormatter.format(messageQuitExtra, user, reason);
}
@NonNull
public CharSequence formatKill(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageKill, user, channel);
}
@NonNull
public CharSequence formatKick(@NonNull CharSequence user, @NonNull CharSequence kicked) {
return SpanFormatter.format(messageKick, user, kicked);
}
@NonNull
public CharSequence formatKick(@NonNull CharSequence user, @NonNull CharSequence kicked, @Nullable CharSequence reason) {
if (reason == null || reason.length() == 0) return formatKick(user, kicked);
return SpanFormatter.format(messageKickExtra, user, kicked, reason);
}
@NonNull
public CharSequence formatMode(@NonNull CharSequence mode, @NonNull CharSequence user) {
return SpanFormatter.format(messageMode, mode, user);
}
@NonNull
public CharSequence formatNick(@NonNull CharSequence newNick) {
return SpanFormatter.format(messageNickSelf, newNick);
}
@NonNull
public CharSequence formatNick(@NonNull CharSequence oldNick, @Nullable CharSequence newNick) {
if (newNick == null || newNick.length() == 0) return formatNick(oldNick);
return SpanFormatter.format(messageNickOther, oldNick, newNick);
}
@NonNull
public CharSequence formatDayChange(@NonNull CharSequence day) {
return SpanFormatter.format(messageDaychange, day);
}
@NonNull
public CharSequence formatAction(@NonNull CharSequence user, @NonNull CharSequence channel) {
return SpanFormatter.format(messageAction, user, channel);
}
@NonNull
public CharSequence formatPlain(@NonNull CharSequence nick, @NonNull CharSequence message) {
return SpanFormatter.format(messagePlain, nick, message);
}
}
public static class Colors {
@AutoColor(android.R.color.transparent)
@ColorInt
......@@ -765,6 +775,10 @@ public class ThemeUtil {
@ColorInt
public int colorTintHighlight;
@AutoColor(R.attr.material_drawer_selected)
@ColorInt
public int colorSelected;
@AutoDimen(R.attr.actionBarSize)
@ColorInt
public int actionBarSize;
......
......@@ -119,7 +119,7 @@ public class IrcFormatDeserializer {
FormatDescription italic = null;
FormatDescription underline = null;
FormatDescription color = null;
boolean colorize = context.settings().mircColors.get();
boolean colorize = context.settings().preferenceColors.get();
// Iterating over every character
for (int i = 0; i < str.length(); i++) {
......
......@@ -26,18 +26,21 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.app.AppCompatActivity;
import de.kuschku.libquassel.BusProvider;
import de.kuschku.quasseldroid_ng.service.ClientBackgroundThread;
import de.kuschku.quasseldroid_ng.service.QuasselService;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.chat.util.ServiceHelper;
import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
import de.kuschku.quasseldroid_ng.ui.theme.AppTheme;
import de.kuschku.util.accounts.Account;
public abstract class BoundActivity extends AppCompatActivity {
protected AppContext context = new AppContext();
@StyleRes
private int themeId;
private QuasselService.LocalBinder binder;
private ServiceConnection connection = new ServiceConnection() {
@Override
......@@ -58,17 +61,21 @@ public abstract class BoundActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
ServiceHelper.initTheme(context, this);
context.withSettings(new Settings(this));
context.settings().theme.addChangeListener(s -> recreate());
themeId = ServiceHelper.initTheme(context, this);
super.onCreate(savedInstanceState);
context.settings().preferenceTheme.addChangeListener(s -> recreate());
ServiceHelper.startServiceIfNotRunning(this);
ServiceHelper.connectToService(this, connection);
}
@Override
protected void onResume() {
super.onResume();
ServiceHelper.connectToService(this, connection);
if (themeId != AppTheme.themeFromString(context.settings().preferenceTheme.get()).themeId) {
finish();
startActivity(getIntent());
}
}
@Override
......
......@@ -31,7 +31,6 @@ import android.support.v4.app.Fragment;
import de.kuschku.libquassel.BusProvider;
import de.kuschku.quasseldroid_ng.service.ClientBackgroundThread;
import de.kuschku.quasseldroid_ng.service.QuasselService;
import de.kuschku.quasseldroid_ng.ui.chat.Settings;
import de.kuschku.quasseldroid_ng.ui.chat.util.ServiceHelper;
import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
import de.kuschku.util.accounts.Account;
......@@ -59,7 +58,6 @@ public abstract class BoundFragment extends Fragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
ServiceHelper.initTheme(context, getActivity());
context.withSettings(new Settings(getActivity()));
super.onCreate(savedInstanceState);
ServiceHelper.startServiceIfNotRunning(getContext());
}
......
/*
* QuasselDroid - Quassel client for Android
* Copyright (C) 2016 Janne Koschinski
* Copyright (C) 2016 Ken Børge Viktil
* Copyright (C) 2016 Magnus Fjell
* Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.util.ui.preferences;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
public class MaterialListPreference extends com.afollestad.materialdialogs.prefs.MaterialListPreference {
public MaterialListPreference(Context context) {
super(context);
setSummary(getEntry());
}
public MaterialListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setSummary(getEntry());
}
public MaterialListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSummary(getEntry());
}
public MaterialListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setSummary(getEntry());
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
setSummary(getEntry());
}
@Override
protected void onBindView(View view) {
setSummary(getEntry());
super.onBindView(view);
}
}
/*
* QuasselDroid - Quassel client for Android
* Copyright (C) 2016 Janne Koschinski
* Copyright (C) 2016 Ken Børge Viktil
* Copyright (C) 2016 Magnus Fjell
* Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.util.ui.preferences;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.Preference;
import android.support.v7.widget.AppCompatSeekBar;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import de.kuschku.quasseldroid_ng.R;
public class SeekBarPreference extends Preference implements OnSeekBarChangeListener {
private static final String ANDROIDNS = "http://schemas.android.com/apk/res/android";
private static final String APPLICATIONNS = "http://robobunny.com";
private static final int DEFAULT_VALUE = 50;
private final String TAG = getClass().getName();
private int mMaxValue = 100;
private int mMinValue = 0;
private int mInterval = 1;
private int mCurrentValue;
private String mUnitsLeft = "";
private String mUnitsRight = "";
private AppCompatSeekBar mSeekBar;
private TextView mStatusText;
public SeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
initPreference(context, attrs);
}
public SeekBarPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initPreference(context, attrs);
}
private void initPreference(Context context, AttributeSet attrs) {
setValuesFromXml(attrs);
mSeekBar = new AppCompatSeekBar(context, attrs);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
setWidgetLayoutResource(R.layout.seek_bar_preference);
}
private void setValuesFromXml(AttributeSet attrs) {
mMaxValue = attrs.getAttributeIntValue(ANDROIDNS, "max", 100);
mMinValue = attrs.getAttributeIntValue(APPLICATIONNS, "min", 0);
mUnitsLeft = getAttributeStringValue(attrs, APPLICATIONNS, "unitsLeft", "");
String units = getAttributeStringValue(attrs, APPLICATIONNS, "units", "");
mUnitsRight = getAttributeStringValue(attrs, APPLICATIONNS, "unitsRight", units);
try {
String newInterval = attrs.getAttributeValue(APPLICATIONNS, "interval");
if (newInterval != null)
mInterval = Integer.parseInt(newInterval);
} catch (Exception e) {
Log.e(TAG, "Invalid interval value", e);
}
}
private String getAttributeStringValue(AttributeSet attrs, String namespace, String name, String defaultValue) {
String value = attrs.getAttributeValue(namespace, name);
if (value == null)
value = defaultValue;
return value;
}
@Override
protected View onCreateView(ViewGroup parent) {
View view = super.onCreateView(parent);
// The basic preference layout puts the widget frame to the right of the title and summary,
// so we need to change it a bit - the seekbar should be under them.
LinearLayout layout = (LinearLayout) view;
layout.setOrientation(LinearLayout.VERTICAL);
return view;
}
@Override
public void onBindView(View view) {
super.onBindView(view);
if (view != null) {
mSeekBar = (AppCompatSeekBar) view.findViewById(R.id.seekBarPrefSeekBar);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setOnSeekBarChangeListener(this);
}
updateView(view);
}
/**
* Update a SeekBarPreference view with our current state
*
* @param view
*/
protected void updateView(View view) {
try {
mStatusText = (TextView) view.findViewById(R.id.seekBarPrefValue);
mStatusText.setText(String.valueOf(mCurrentValue));
mStatusText.setMinimumWidth(30);
mSeekBar.setProgress(mCurrentValue - mMinValue);
} catch (Exception e) {
Log.e(TAG, "Error updating seek bar preference", e);
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int newValue = progress + mMinValue;
if (newValue > mMaxValue)
newValue = mMaxValue;
else if (newValue < mMinValue)
newValue = mMinValue;
else if (mInterval != 1 && newValue % mInterval != 0)
newValue = Math.round(((float) newValue) / mInterval) * mInterval;
// change rejected, revert to the previous value
if (!callChangeListener(newValue)) {
seekBar.setProgress(mCurrentValue - mMinValue);
return;
}
// change accepted, store it
mCurrentValue = newValue;
mStatusText.setText(String.valueOf(newValue));
persistInt(newValue);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
notifyChanged();
}
@Override
protected Object onGetDefaultValue(TypedArray ta, int index) {
int defaultValue = ta.getInt(index, DEFAULT_VALUE);
return defaultValue;
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
if (restoreValue) {
mCurrentValue = getPersistedInt(mCurrentValue);
} else {
int temp = 0;
try {
temp = (Integer) defaultValue;
} catch (Exception ex) {
Log.e(TAG, "Invalid default value: " + defaultValue.toString());
}
persistInt(temp);
mCurrentValue = temp;
}
}
/**
* make sure that the seekbar is disabled if the preference is disabled
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
mSeekBar.setEnabled(enabled);
}
@Override
public void onDependencyChanged(Preference dependency, boolean disableDependent) {
super.onDependencyChanged(dependency, disableDependent);
//Disable movement of seek bar when dependency is false
if (mSeekBar != null) {
mSeekBar.setEnabled(!disableDependent);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment