improve preference screen

remove unused resources
development
Felix Prahl-Kamps 2019-10-10 13:51:24 +02:00
parent e9176e2a5b
commit 1454b6d19c
16 changed files with 92 additions and 231 deletions

View File

@ -38,16 +38,16 @@ import lu.circl.mispbump.models.restModels.User;
public class HomeActivity extends AppCompatActivity {
private List<SyncInformation> syncInformationList;
private PreferenceManager preferenceManager;
private MispRestClient restClient;
private SwipeRefreshLayout swipeRefreshLayout;
private List<SyncInformation> syncInformationList;
private RecyclerView recyclerView;
private SyncInfoAdapter syncInfoAdapter;
private TextView emptyRecyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -102,7 +102,7 @@ public class HomeActivity extends AppCompatActivity {
swipeRefreshLayout = findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setOnRefreshListener(() -> {
checkUnimportedSyncs();
onSwipeRefresh();
syncInfoAdapter.setItems(syncInformationList);
});
@ -174,7 +174,12 @@ public class HomeActivity extends AppCompatActivity {
}
}
private void checkUnimportedSyncs() {
private void onSwipeRefresh() {
if (preferenceManager.getShowLocalSyncsOnly()) {
swipeRefreshLayout.setRefreshing(false);
return;
}
restClient.getAllServers(new MispRestClient.AllRawServersCallback() {
@Override
public void success(List<MispServer> mispServers) {

View File

@ -1,15 +1,19 @@
package lu.circl.mispbump.activities;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import lu.circl.mispbump.R;
import lu.circl.mispbump.auxiliary.PreferenceManager;
@ -17,19 +21,11 @@ import lu.circl.mispbump.auxiliary.PreferenceManager;
public class PreferenceActivity extends AppCompatActivity {
private PreferenceManager preferenceManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preference);
preferenceManager = PreferenceManager.getInstance(PreferenceActivity.this);
initializeViews();
}
private void initializeViews() {
Toolbar myToolbar = findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
@ -37,29 +33,66 @@ public class PreferenceActivity extends AppCompatActivity {
assert ab != null;
ab.setDisplayHomeAsUpEnabled(true);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
PreferencesFragment preferencesFragment = new PreferencesFragment();
// preferencesFragment.onDeleteAllSyncsListener = preference -> {
// preferenceManager.clearUploadInformation();
// return true;
// };
fragmentTransaction.add(R.id.fragmentContainer, preferencesFragment, PreferencesFragment.class.getSimpleName());
fragmentTransaction.commit();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragmentContainer, new PreferencesFragment(PreferenceActivity.this))
.commit();
}
public static class PreferencesFragment extends PreferenceFragmentCompat {
private Preference.OnPreferenceClickListener onDeleteAllSyncsListener;
private Context context;
private PreferenceManager preferenceManager;
PreferencesFragment(Context context) {
this.context = context;
preferenceManager = PreferenceManager.getInstance(context);
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preference_screen_main, rootKey);
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context);
setPreferenceScreen(preferenceScreen);
// Preference deleteAllSyncInfo = findPreference("PREF_DELETE_ALL_SYNCS");
// assert deleteAllSyncInfo != null;
// deleteAllSyncInfo.setOnPreferenceClickListener(onDeleteAllSyncsListener);
// General
PreferenceCategory generalCategory = new PreferenceCategory(context);
generalCategory.setTitle("General");
getPreferenceScreen().addPreference(generalCategory);
SwitchPreference fetchOnlyLocalSyncs = new SwitchPreference(context);
fetchOnlyLocalSyncs.setTitle("Display local syncs only");
fetchOnlyLocalSyncs.setSummaryOn("Only those syncs that were made with MISPbump are displayed.");
fetchOnlyLocalSyncs.setSummaryOff("Existing syncs from your MISP instance are fetched, too.");
fetchOnlyLocalSyncs.setChecked(preferenceManager.getShowLocalSyncsOnly());
fetchOnlyLocalSyncs.setOnPreferenceChangeListener((preference, newValue) -> {
preferenceManager.setShowLocalSyncsOnly((boolean) newValue);
return true;
});
generalCategory.addPreference(fetchOnlyLocalSyncs);
// App Information
PreferenceCategory appInfoCategory = new PreferenceCategory(context);
appInfoCategory.setTitle("App Information");
getPreferenceScreen().addPreference(appInfoCategory);
Preference githubPreference = new Preference(context);
githubPreference.setIcon(context.getDrawable(R.drawable.ic_github));
githubPreference.setTitle("Github");
githubPreference.setSummary("Visit the Github project");
Intent viewOnGithub = new Intent(Intent.ACTION_VIEW);
viewOnGithub.setData(Uri.parse("https://github.com/MISP/misp-bump"));
githubPreference.setIntent(viewOnGithub);
Preference versionPreference = new Preference(context);
versionPreference.setIcon(context.getDrawable(R.drawable.ic_info_outline_dark));
versionPreference.setTitle("Version");
versionPreference.setSummary("1.0");
appInfoCategory.addPreference(githubPreference);
appInfoCategory.addPreference(versionPreference);
}
}
}

View File

@ -37,12 +37,16 @@ public class PreferenceManager {
private static final String USER_ORG_INFOS = "user_org_infos";
private static final String SYNC_INFO = "sync_info";
private static final String MISP_ROLES = "misp_roles";
private static final String SHOW_MISPBUMP_SYNCS_ONLY = "show_mispbump_syncs_only";
private SharedPreferences preferences;
private static PreferenceManager instance;
private List<SyncInformation> cachedSyncInformationList;
private PreferenceManager(Context context) {
preferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@ -146,15 +150,7 @@ public class PreferenceManager {
SharedPreferences.Editor editor = preferences.edit();
editor.putString(USER_ORG_INFOS, encrypted);
editor.apply();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
} catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
e.printStackTrace();
}
@ -175,17 +171,7 @@ public class PreferenceManager {
KeyStoreWrapper keyStoreWrapper = new KeyStoreWrapper(KeyStoreWrapper.USER_ORGANISATION_INFO_ALIAS);
String decrypted = keyStoreWrapper.decrypt(preferences.getString(USER_ORG_INFOS, ""));
return new Gson().fromJson(decrypted, Organisation.class);
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
} catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
e.printStackTrace();
}
@ -223,8 +209,6 @@ public class PreferenceManager {
}
private List<SyncInformation> cachedSyncInformationList;
private void loadSyncInformationList() {
KeyStoreWrapper ksw = new KeyStoreWrapper(KeyStoreWrapper.SYNC_INFORMATION_ALIAS);
String storedSyncInfoString = preferences.getString(SYNC_INFO, null);
@ -282,6 +266,11 @@ public class PreferenceManager {
return null;
}
/**
* Add or update a {@link SyncInformation} to local storage
*
* @param syncInformation to be added
*/
public void addSyncInformation(SyncInformation syncInformation) {
if (cachedSyncInformationList == null) {
loadSyncInformationList();
@ -330,11 +319,20 @@ public class PreferenceManager {
}
public boolean getShowLocalSyncsOnly() {
return preferences.getBoolean(SHOW_MISPBUMP_SYNCS_ONLY, true);
}
public void setShowLocalSyncsOnly(boolean showLocalSyncsOnly) {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(SHOW_MISPBUMP_SYNCS_ONLY, showLocalSyncsOnly);
editor.apply();
}
public void clearAllData() {
SharedPreferences.Editor editor = preferences.edit();
// clearServerUrl();
// clearAutomationKey();
clearUploadInformation();
editor.clear();

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="@android:integer/config_shortAnimTime"
/>
</set>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="@android:integer/config_shortAnimTime"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="300"
/>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="300"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="300"
/>
</set>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="10%"
android:toXScale="1.0"
android:toYScale="1.0"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="50%p"
android:toXDelta="0"
android:duration="@android:integer/config_mediumAnimTime"
/>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-50%p"
android:duration="@android:integer/config_mediumAnimTime"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:interpolator/accelerate_cubic"
android:duration="300"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType"
/>
</set>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:interpolator/accelerate_cubic"
android:duration="300"
android:propertyName="x"
android:valueFrom="-1000"
android:valueTo="0"
android:valueType="floatType"
/>
</set>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="300"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="1000"
android:valueType="floatType"
/>
</set>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="300"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType"
/>
</set>

View File

@ -42,9 +42,7 @@
app:layout_constraintEnd_toStartOf="@id/material_preference_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/material_preference_title"
tools:text="Subtitle"
android:inAnimation="@anim/push_up_in"
android:outAnimation="@anim/push_up_out"/>
tools:text="Subtitle" />
<Switch
android:id="@+id/material_preference_switch"

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- <PreferenceCategory android:title="@string/preference_category_general">-->
<!-- <Preference-->
<!-- android:key="PREF_DELETE_ALL_SYNCS"-->
<!-- android:icon="@drawable/ic_delete_forever"-->
<!-- android:title="@string/preference_delete_all_syncs"-->
<!-- android:summary="@string/preference_delete_all_syncs_summary"/>-->
<!-- </PreferenceCategory>-->
<PreferenceCategory android:title="@string/preference_category_information">
<Preference
android:icon="@drawable/ic_github"
android:title="Github"
android:summary="@string/preference_github_summary">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/MISP/misp-bump"/>
</Preference>
<Preference
android:icon="@drawable/ic_info_outline_dark"
android:title="Version"
android:summary="1.1.2"/>
</PreferenceCategory>
</PreferenceScreen>