Skip to content

Commit fff6410

Browse files
authored
Merge pull request #149 from concaveNP/deal-with-saving-info-out-when-screen-is-rotated
Deal with saving info out when screen is rotated
2 parents acd14b5 + 2cebe21 commit fff6410

28 files changed

+196
-57
lines changed

ArtistryMuse/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ArtistryMuse/.idea/misc.xml

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ArtistryMuse/app/build.gradle

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
apply plugin: 'com.android.application'
2222

23-
// Load keystore from a properties file in the root of the project directory
24-
def keystorePropertiesFile = rootProject.file("keystore.properties");
25-
def keystoreProperties = new Properties()
26-
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
27-
2823
android {
2924
signingConfigs {
3025
release {
@@ -34,16 +29,9 @@ android {
3429
storePassword '6tS4m6WzyTBQdmyQ9Jbj'
3530
}
3631
}
37-
// signingConfigs {
38-
// release {
39-
// keyAlias keystoreProperties['keyAlias']
40-
// keyPassword keystoreProperties['keyPassword']
41-
// storeFile file(keystoreProperties['storeFile'])
42-
// storePassword keystoreProperties['storePassword']
43-
// }
44-
// }
32+
4533
compileSdkVersion 26
46-
buildToolsVersion '26.0.1'
34+
buildToolsVersion '26.0.2'
4735
defaultConfig {
4836
applicationId "com.concavenp.artistrymuse"
4937
minSdkVersion 17
@@ -83,8 +71,6 @@ dependencies {
8371
compile 'com.google.firebase:firebase-database:11.2.0'
8472
compile 'com.google.firebase:firebase-crash:11.2.0'
8573
compile 'com.google.android.gms:play-services-auth:11.2.0'
86-
compile 'com.google.android.gms:play-services:11.2.0'
87-
compile 'com.google.gms:google-services:3.1.0'
8874
compile 'com.firebaseui:firebase-ui-database:2.3.0'
8975
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
9076
compile 'com.firebaseui:firebase-ui-storage:2.3.0'
@@ -93,12 +79,12 @@ dependencies {
9379
compile 'pub.devrel:easypermissions:0.2.0'
9480
compile 'com.android.support:multidex:1.0.1'
9581
compile 'com.android.support:mediarouter-v7:26.0.1'
96-
compile 'com.android.support:design:26.0.0-alpha1'
97-
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
98-
compile 'com.android.support:support-v4:26.0.0-alpha1'
99-
compile 'com.android.support:support-vector-drawable:26.0.0-alpha1'
82+
compile 'com.android.support:design:26.0.1'
83+
compile 'com.android.support:appcompat-v7:26.0.1'
84+
compile 'com.android.support:support-v4:26.0.1'
85+
compile 'com.android.support:support-vector-drawable:26.0.1'
10086
testCompile 'junit:junit:4.12'
101-
compile 'com.android.support:gridlayout-v7:26.0.0-alpha1'
87+
compile 'com.android.support:gridlayout-v7:26.0.1'
10288
}
10389

10490
// ADD THIS AT THE BOTTOM

ArtistryMuse/app/src/main/java/com/concavenp/artistrymuse/fragments/FavoritesFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
8989
mainView = inflater.inflate(R.layout.fragment_favorites, container, false);
9090

9191
return mainView;
92+
9293
}
9394

9495
@Override

ArtistryMuse/app/src/main/java/com/concavenp/artistrymuse/fragments/GalleryFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
9797
// Inflate the layout for this fragment
9898
mainView = inflater.inflate(R.layout.fragment_gallery, container, false);
9999

100-
101100
return mainView;
101+
102102
}
103103

104104
@Override

ArtistryMuse/app/src/main/java/com/concavenp/artistrymuse/fragments/SearchFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public class SearchFragment extends BaseFragment {
7373
* results or a informative message stating that a search needs to be performed to find results.
7474
*/
7575
private ViewFlipper mFlipper;
76+
7677
/**
7778
* The Shared Preferences key lookup value for identifying the last used tab position.
7879
*/
7980
private static final String SEARCH_STRING = "SEARCH_STRING";
80-
private String mSearchString = "";
81+
private static final String FLIP_ACTIVE_SEARCH_STRING = "FLIP_ACTIVE_SEARCH_STRING";
8182

8283
/**
8384
* Use this factory method to create a new instance of
@@ -230,6 +231,7 @@ public void onSaveInstanceState(Bundle outState) {
230231
super.onSaveInstanceState(outState);
231232

232233
outState.putString(SEARCH_STRING,mSearchEditText.getText().toString());
234+
outState.putInt(FLIP_ACTIVE_SEARCH_STRING, mFlipper.getDisplayedChild());
233235

234236
}
235237

@@ -246,6 +248,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
246248
if (savedInstanceState != null) {
247249

248250
mSearchEditText.setText(savedInstanceState.getString(SEARCH_STRING, ""));
251+
mFlipper.setDisplayedChild(savedInstanceState.getInt(FLIP_ACTIVE_SEARCH_STRING, 0));
249252

250253
}
251254

ArtistryMuse/app/src/main/java/com/concavenp/artistrymuse/fragments/SearchResultFragment.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.concavenp.artistrymuse.fragments;
2222

2323
import android.os.Bundle;
24+
import android.support.annotation.Nullable;
2425
import android.support.v4.app.Fragment;
2526
import android.support.v7.widget.RecyclerView;
2627
import android.support.v7.widget.StaggeredGridLayoutManager;
@@ -50,6 +51,12 @@
5051
import com.google.firebase.database.Query;
5152
import com.google.firebase.database.ValueEventListener;
5253

54+
import java.io.ByteArrayInputStream;
55+
import java.io.ByteArrayOutputStream;
56+
import java.io.IOException;
57+
import java.io.ObjectInputStream;
58+
import java.io.ObjectOutputStream;
59+
import java.util.List;
5360
import java.util.UUID;
5461

5562
/**
@@ -81,6 +88,12 @@ public class SearchResultFragment extends BaseFragment implements SearchFragment
8188

8289
private String mSearchText;
8390

91+
/**
92+
* The Shared Preferences key lookup value for identifying the last used tab position.
93+
*/
94+
private static final String SEARCH_STRING = "SEARCH_STRING_";
95+
private static final String FLIP_ACTIVE_SEARCH_STRING = "FLIP_ACTIVE_SEARCH_STRING";
96+
8497
// This flipper allows the content of the fragment to show the user either the list search
8598
// results or a informative message stating that a search needs to be performed to find
8699
// results.
@@ -397,6 +410,86 @@ private Query getResponseQuery(DatabaseReference databaseReference, UUID uuid) {
397410

398411
}
399412

413+
/**
414+
* Save off the User entered search string.
415+
*
416+
* @param outState - The bundle that will be presented to this fragment upon re-creation
417+
*/
418+
@Override
419+
public void onSaveInstanceState(Bundle outState) {
420+
421+
super.onSaveInstanceState(outState);
422+
423+
outState.putInt(FLIP_ACTIVE_SEARCH_STRING + getDatabaseNameFromType(), mFlipper.getDisplayedChild());
424+
425+
try {
426+
switch (mType) {
427+
case USERS: {
428+
List<UserResponseHit> list = mUsersAdapter.getData();
429+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
430+
ObjectOutputStream oos = new ObjectOutputStream(baos);
431+
oos.writeObject(list);
432+
outState.putByteArray(SEARCH_STRING + getDatabaseNameFromType(), baos.toByteArray());
433+
break;
434+
}
435+
case PROJECTS: {
436+
List<ProjectResponseHit> list = mProjectsAdapter.getData();
437+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
438+
ObjectOutputStream oos = new ObjectOutputStream(baos);
439+
oos.writeObject(list);
440+
outState.putByteArray(SEARCH_STRING + getDatabaseNameFromType(), baos.toByteArray());
441+
break;
442+
}
443+
}
444+
} catch (IOException e) {
445+
e.printStackTrace();
446+
}
447+
448+
}
449+
450+
/**
451+
* Restore the instance data saved. This includes the User entered search string.
452+
*
453+
* @param savedInstanceState - The bundle of instance data saved
454+
*/
455+
@Override
456+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
457+
458+
super.onActivityCreated(savedInstanceState);
459+
460+
if (savedInstanceState != null) {
461+
462+
mFlipper.setDisplayedChild(savedInstanceState.getInt(FLIP_ACTIVE_SEARCH_STRING + getDatabaseNameFromType(), 0));
463+
464+
try {
465+
switch (mType) {
466+
case USERS: {
467+
ByteArrayInputStream bais = new ByteArrayInputStream(savedInstanceState.getByteArray(SEARCH_STRING + getDatabaseNameFromType()));
468+
ObjectInputStream ois = new ObjectInputStream(bais);
469+
List<UserResponseHit> list = (List<UserResponseHit>) ois.readObject();
470+
mUsersAdapter.clearData();
471+
mUsersAdapter.add(list);
472+
break;
473+
}
474+
case PROJECTS: {
475+
ByteArrayInputStream bais = new ByteArrayInputStream(savedInstanceState.getByteArray(SEARCH_STRING + getDatabaseNameFromType()));
476+
ObjectInputStream ois = new ObjectInputStream(bais);
477+
List<ProjectResponseHit> list = (List<ProjectResponseHit>) ois.readObject();
478+
mProjectsAdapter.clearData();
479+
mProjectsAdapter.add(list);
480+
break;
481+
}
482+
}
483+
} catch (IOException e) {
484+
e.printStackTrace();
485+
} catch (ClassNotFoundException e) {
486+
e.printStackTrace();
487+
}
488+
489+
}
490+
491+
}
492+
400493
@Override
401494
public void onSearchInteraction(String searchString) {
402495

ArtistryMuse/app/src/main/java/com/concavenp/artistrymuse/fragments/adapter/SearchResultAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public int getItemCount() {
114114

115115
}
116116

117+
public List<E> getData() {
118+
119+
return mResultItems;
120+
121+
}
122+
117123
public void add(List<E> results) {
118124

119125
mResultItems.addAll(results);

ArtistryMuse/app/src/main/res/menu/menu_inspiration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
<item
2525
android:id="@+id/action_save"
2626
android:orderInCategory="100"
27-
android:title="Save"
27+
android:title="@string/save"
2828
app:showAsAction="always"/>
2929
</menu>

ArtistryMuse/app/src/main/res/menu/menu_profile.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
<item
2525
android:id="@+id/action_save"
2626
android:orderInCategory="100"
27-
android:title="Save"
27+
android:title="@string/save"
2828
app:showAsAction="always"/>
2929
</menu>

0 commit comments

Comments
 (0)