recyclerview with notification list
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package net.headlezz.notificationlogger.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class BlacklistFragment extends Fragment {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.headlezz.notificationlogger.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||
import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
|
||||
|
||||
import net.headlezz.notificationlogger.R;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class PreferenceActivity extends AppCompatActivity implements PreferenceFragment.PreferenceCallbacks {
|
||||
|
||||
@Bind(R.id.toolbar)
|
||||
Toolbar mToolbar;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.preference_activity);
|
||||
ButterKnife.bind(this);
|
||||
setSupportActionBar(mToolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
if(getSupportFragmentManager().findFragmentById(R.id.fragment_holder) == null) {
|
||||
showSettingsScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showAboutScreen() {
|
||||
// TODO add other libraries
|
||||
LibsSupportFragment aboutFrag = new LibsBuilder()
|
||||
.withAboutAppName(getString(R.string.app_name))
|
||||
.withAboutIconShown(true)
|
||||
.withAboutVersionShown(true)
|
||||
.withAboutVersionShownCode(true)
|
||||
.supportFragment();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_holder, aboutFrag)
|
||||
.addToBackStack("about")
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBlacklistScreen() {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_holder, new BlacklistFragment())
|
||||
.addToBackStack("blacklist")
|
||||
.commit();
|
||||
getSupportActionBar().setTitle(getString(R.string.title_blacklist));
|
||||
}
|
||||
|
||||
public void showSettingsScreen() {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_holder, new PreferenceFragment())
|
||||
.commit();
|
||||
getSupportActionBar().setTitle(getString(R.string.title_settings));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if(getSupportFragmentManager().getBackStackEntryCount() > 0)
|
||||
getSupportActionBar().setTitle(getString(R.string.title_settings));
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package net.headlezz.notificationlogger.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
|
||||
import net.headlezz.notificationlogger.R;
|
||||
import net.headlezz.notificationlogger.logger.Logged_notificationTable;
|
||||
|
||||
public class PreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private PreferenceCallbacks mCallbacks;
|
||||
|
||||
final String PREF_ABOUT = "pref_about";
|
||||
final String PREF_BLACKLIST = "pref_blacklist";
|
||||
final String PREF_CLEAR_DATABASE = "pref_clear_database";
|
||||
|
||||
|
||||
interface PreferenceCallbacks {
|
||||
void showAboutScreen();
|
||||
void showBlacklistScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
findPreference(PREF_ABOUT).setOnPreferenceClickListener(this);
|
||||
findPreference(PREF_BLACKLIST).setOnPreferenceClickListener(this);
|
||||
findPreference(PREF_CLEAR_DATABASE).setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
if(key.equals(PREF_ABOUT)) {
|
||||
mCallbacks.showAboutScreen();
|
||||
return true;
|
||||
} else if(key.equals(PREF_BLACKLIST)) {
|
||||
mCallbacks.showBlacklistScreen();
|
||||
return true;
|
||||
} else if(key.equals(PREF_CLEAR_DATABASE))
|
||||
askClearDatabase();
|
||||
return false;
|
||||
}
|
||||
|
||||
private void askClearDatabase() {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.pref_clear_database_dialog_title)
|
||||
.setMessage(R.string.pref_clear_database_dialog_message)
|
||||
.setNegativeButton(R.string.pref_clear_database_dialog_negative, null)
|
||||
.setPositiveButton(R.string.pref_clear_database_dialog_positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
clearDatabase();
|
||||
}
|
||||
})
|
||||
.create().show();
|
||||
}
|
||||
|
||||
private void clearDatabase() {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
ContentResolver resolver = getContext().getContentResolver();
|
||||
// there are no notifications with negative ids, so we use this to select all rows
|
||||
String whereClause = Logged_notificationTable.FIELD_NOTIFICATION_ID + " != -1";
|
||||
resolver.delete(Logged_notificationTable.CONTENT_URI, whereClause, new String[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if(getActivity() != null)
|
||||
Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.pref_clear_database_snackbar_cleared, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mCallbacks = (PreferenceCallbacks) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mCallbacks = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user