Skip to content

Commit

Permalink
updated shared pref change listener, adjusted UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chaneylc committed Mar 7, 2018
1 parent 10578a8 commit 37e87b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
28 changes: 24 additions & 4 deletions app/src/main/java/org/phenoapps/verify/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class MainActivity extends AppCompatActivity {

private IdEntryDbHelper mDbHelper;

private SharedPreferences.OnSharedPreferenceChangeListener mPrefListener;

//database prepared statements
private SQLiteStatement sqlUpdateNote;
private SQLiteStatement sqlDeleteId;
Expand Down Expand Up @@ -95,16 +97,34 @@ protected void onCreate(Bundle savedInstanceState) {
mIds = new SparseArray<>();

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

final View auxInfo = findViewById(R.id.auxScrollView);
final View auxValue = findViewById(R.id.auxValueView);

if (sharedPref.getBoolean(SettingsActivity.AUX_INFO, false)) {
auxInfo.setVisibility(View.VISIBLE);
auxValue.setVisibility(View.VISIBLE);

} else {
auxInfo.setVisibility(View.GONE);
auxValue.setVisibility(View.GONE);
}

sharedPref.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
View auxInfo = findViewById(R.id.auxValueView);

if (sharedPreferences.getBoolean(SettingsActivity.AUX_INFO, false)) {
auxInfo.setVisibility(View.VISIBLE);
} else auxInfo.setVisibility(View.GONE);
auxValue.setVisibility(View.VISIBLE);
} else {
auxInfo.setVisibility(View.GONE);
auxValue.setVisibility(View.GONE);
}
}
});
};

sharedPref.registerOnSharedPreferenceChangeListener(mPrefListener);

if (!sharedPref.getBoolean("onlyLoadTutorialOnce", false)) {
launchIntro();
Expand Down
42 changes: 29 additions & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.constraint.ConstraintLayout
android:id="@+id/constraint_layout_parent"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -29,7 +31,6 @@
android:inputType="text"
android:maxLines="1"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/idTable" />
Expand All @@ -38,6 +39,7 @@
android:id="@+id/clearButton"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
Expand All @@ -48,47 +50,61 @@

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="216dp"
android:layout_marginBottom="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scannerTextView">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_weight="0.5"
android:fillViewport="true">
android:fillViewport="true"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/valueView"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:visibility="visible" />

</ScrollView>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#66eec657" />
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#66eec657"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/auxScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:fillViewport="true">
android:fillViewport="true"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/scrollView">

<TextView
android:id="@+id/auxValueView"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:visibility="visible" />

</ScrollView>
</LinearLayout>
Expand Down

0 comments on commit 37e87b1

Please sign in to comment.