forked from upstream-mirrors/quik
Migrate settings to separate activity
This commit is contained in:
@@ -98,6 +98,8 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ui.settings.SettingsActivity" />
|
||||
|
||||
<activity-alias
|
||||
android:name=".ui.MainActivity-Teal"
|
||||
android:enabled="true"
|
||||
|
||||
@@ -28,7 +28,6 @@ import butterknife.ButterKnife;
|
||||
import com.google.android.mms.pdu_alt.PduHeaders;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.ConversationPrefsHelper;
|
||||
import com.moez.QKSMS.common.DialogHelper;
|
||||
import com.moez.QKSMS.common.DonationManager;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.common.QKRateSnack;
|
||||
@@ -234,19 +233,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onKeyUp(KeyEvent.KEYCODE_BACK, null);
|
||||
break;
|
||||
case R.id.menu_settings:
|
||||
switchContent(SettingsFragment.newInstance(R.xml.settings_main), true);
|
||||
break;
|
||||
return true;
|
||||
case R.id.menu_search:
|
||||
switchContent(new SearchFragment(), true);
|
||||
break;
|
||||
case R.id.menu_changelog:
|
||||
DialogHelper.showChangelog(this);
|
||||
break;
|
||||
case R.id.menu_donate:
|
||||
DonationManager.getInstance(this).showDonateDialog();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
@@ -303,13 +293,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (!mSlidingMenu.isMenuShowing()) {
|
||||
Fragment category = getFragmentManager().findFragmentByTag(SettingsFragment.CATEGORY_TAG);
|
||||
if (category != null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.content_frame, SettingsFragment.newInstance(R.xml.settings_main)).commit();
|
||||
} else {
|
||||
mSlidingMenu.showMenu();
|
||||
}
|
||||
mSlidingMenu.showMenu();
|
||||
return true;
|
||||
} else {
|
||||
if (mConversationList.isShowingBlocked()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.moez.QKSMS.ui.base;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PorterDuff;
|
||||
@@ -23,10 +24,14 @@ import android.widget.Toast;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.moez.QKSMS.QKSMSApp;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.common.DialogHelper;
|
||||
import com.moez.QKSMS.common.DonationManager;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.common.utils.ColorUtils;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.ui.ThemeManager;
|
||||
import com.moez.QKSMS.ui.search.SearchFragment;
|
||||
import com.moez.QKSMS.ui.settings.SettingsActivity;
|
||||
import com.moez.QKSMS.ui.view.QKTextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -241,6 +246,28 @@ public abstract class QKActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_settings:
|
||||
startActivity(SettingsActivity.class);
|
||||
return true;
|
||||
case R.id.menu_changelog:
|
||||
DialogHelper.showChangelog(this);
|
||||
return true;
|
||||
case R.id.menu_donate:
|
||||
DonationManager.getInstance(this).showDonateDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void startActivity(Class<?> cls) {
|
||||
Intent intent = new Intent(this, cls);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public boolean isScreenOn() {
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.ui.SwipeBackLayout;
|
||||
|
||||
@@ -14,6 +15,7 @@ public abstract class QKSwipeBackActivity extends QKActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fragment);
|
||||
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
getWindow().getDecorView().setBackgroundDrawable(null);
|
||||
@@ -21,12 +23,29 @@ public abstract class QKSwipeBackActivity extends QKActivity {
|
||||
|
||||
mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
|
||||
mSwipeBackLayout.setEnableGesture(true);
|
||||
|
||||
showBackButton(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
mSwipeBackLayout.attachToActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
mSwipeBackLayout.scrollToFinishActivity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,6 @@ public class MessageListActivity extends QKSwipeBackActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fragment);
|
||||
showBackButton(true);
|
||||
|
||||
onNewIntent(getIntent());
|
||||
}
|
||||
|
||||
@@ -117,20 +114,11 @@ public class MessageListActivity extends QKSwipeBackActivity {
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
|
||||
case R.id.menu_donate:
|
||||
DonationManager.getInstance(this).showDonateDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
mSwipeBackLayout.scrollToFinishActivity();
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
||||
private String mHighlight;
|
||||
private boolean mShowImmediate;
|
||||
|
||||
public static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) {
|
||||
protected static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) {
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(ARG_THREAD_ID, threadId);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.moez.QKSMS.ui.settings;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.os.Bundle;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.ui.base.QKSwipeBackActivity;
|
||||
|
||||
public class SettingsActivity extends QKSwipeBackActivity {
|
||||
|
||||
private SettingsFragment mSettingsFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
FragmentManager fm = getFragmentManager();
|
||||
mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.content_frame);
|
||||
if (mSettingsFragment == null) {
|
||||
mSettingsFragment = SettingsFragment.newInstance(R.xml.settings_main);
|
||||
}
|
||||
|
||||
fm.beginTransaction()
|
||||
.replace(R.id.content_frame, mSettingsFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (getFragmentManager().getBackStackEntryCount() > 0) {
|
||||
getFragmentManager().popBackStack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,17 +35,16 @@ import com.moez.QKSMS.common.DialogHelper;
|
||||
import com.moez.QKSMS.common.DonationManager;
|
||||
import com.moez.QKSMS.common.ListviewHelper;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.common.utils.DateFormatter;
|
||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.common.utils.PackageUtils;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
|
||||
import com.moez.QKSMS.transaction.EndlessJabber;
|
||||
import com.moez.QKSMS.transaction.NotificationManager;
|
||||
import com.moez.QKSMS.transaction.SmsHelper;
|
||||
import com.moez.QKSMS.ui.ContentFragment;
|
||||
import com.moez.QKSMS.ui.MainActivity;
|
||||
import com.moez.QKSMS.ui.ThemeManager;
|
||||
import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.dialog.BlockedNumberDialog;
|
||||
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
|
||||
import com.moez.QKSMS.ui.dialog.QKDialog;
|
||||
@@ -65,7 +64,7 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener,
|
||||
Preference.OnPreferenceClickListener, ContentFragment {
|
||||
Preference.OnPreferenceClickListener {
|
||||
private final String TAG = "PreferenceFragment";
|
||||
|
||||
public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance";
|
||||
@@ -163,7 +162,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
public static final String GITHUB_URL = "https://github.com/qklabs/qksms";
|
||||
public static final String CROWDIN_URL = "https://crowdin.com/project/qksms";
|
||||
|
||||
private MainActivity mContext;
|
||||
private QKActivity mContext;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private SharedPreferences mPrefs;
|
||||
private Resources mRes;
|
||||
@@ -186,7 +185,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
|
||||
private int mResource;
|
||||
|
||||
public static SettingsFragment newInstance(int category) {
|
||||
protected static SettingsFragment newInstance(int category) {
|
||||
SettingsFragment fragment = new SettingsFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
@@ -200,11 +199,14 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = getArguments();
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mContext = (MainActivity) getActivity();
|
||||
mContext = (QKActivity) getActivity();
|
||||
mPrefs = mContext.getPrefs();
|
||||
mRes = mContext.getResources();
|
||||
|
||||
mContext.setTitle(R.string.title_settings);
|
||||
|
||||
mResource = args.getInt("category", R.xml.settings);
|
||||
addPreferencesFromResource(mResource);
|
||||
|
||||
@@ -333,6 +335,12 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.settings, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed top level preferences from the layout
|
||||
*/
|
||||
@@ -431,9 +439,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
case NIGHT_START:
|
||||
updateAlarmManager(mContext, true);
|
||||
break;
|
||||
case SLIDING_TAB:
|
||||
mContext.setSlidingTabEnabled((Boolean) newValue);
|
||||
break;
|
||||
case YAPPY:
|
||||
if ((Boolean) newValue) {
|
||||
try {
|
||||
@@ -520,6 +525,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
Fragment fragment = SettingsFragment.newInstance(resId);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.addToBackStack(null)
|
||||
.replace(R.id.content_frame, fragment, CATEGORY_TAG)
|
||||
.commit();
|
||||
}
|
||||
@@ -704,40 +710,4 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
alarmManager.cancel(nightIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentOpening() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentOpened() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentClosing() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentClosed() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuChanging(float percentOpen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) {
|
||||
if (mContext == null) {
|
||||
mContext = (MainActivity) context;
|
||||
mPrefs = mContext.getPrefs();
|
||||
}
|
||||
|
||||
inflater.inflate(R.menu.settings, menu);
|
||||
mContext.setTitle(R.string.title_settings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user