Skip to content

Commit

Permalink
Fixed authentication when not logged in, fixed blank activity on firs…
Browse files Browse the repository at this point in the history
…t open with no data (not logged in), Re-added the tutorial screen (somehow got removed), Sped up startup even more (got rid of loading activity), Fixed opening from background for no reason, Fixed crash when removing actionbar on list mode
  • Loading branch information
SlideCI committed Jan 9, 2016
1 parent 0f24d22 commit 00c4381
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 83 deletions.
9 changes: 4 additions & 5 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -19,8 +19,11 @@
android:theme="@style/yellow_dark">

<activity
android:name=".Activities.LoadingData"
android:name=".Activities.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"

android:label="@string/app_name">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -180,11 +183,7 @@
<activity
android:name=".Activities.Crash"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".Activities.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"

/>
<activity
android:name=".Activities.Settings"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down
Expand Up @@ -34,10 +34,10 @@ public void onCreate(Bundle savedInstance) {
applyColorTheme();

((Reddit) getApplication()).active = true;
((Reddit) getApplication()).loader = this;
// ((Reddit) getApplication()).loader = this;
setContentView(R.layout.activity_loading);
if (SubredditStorage.alphabeticalSubscriptions != null && isNetworkAvailable()) {
((Reddit) getApplication()).startMain();
// ((Reddit) getApplication()).startMain();

} else if (!isNetworkAvailable()) {
AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this);
Expand Down
Expand Up @@ -126,12 +126,16 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
restartTheme();
} else if (requestCode == 3) {
new SubredditStorageNoContext().execute(this);
} else if (requestCode == 4 && resultCode != 4) {
} else if (requestCode == 4 && resultCode != 4) { //what?
if (e != null) {
e.clearFocus();
e.setText("");
drawerLayout.closeDrawers();
}
} else if(requestCode == 55){
doDrawer();

setDataSet(SubredditStorage.subredditsForHome);
}
}

Expand Down Expand Up @@ -213,6 +217,10 @@ protected void onCreate(final Bundle savedInstanceState) {
// result of the request.
}
}
if (!Reddit.colors.contains("Tutorial")) {
Intent i = new Intent(this, Tutorial.class);
startActivityForResult(i, 55);
}

if (savedInstanceState != null && !changed) {

Expand Down Expand Up @@ -408,7 +416,7 @@ public void onClick(View v) {
final Context contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, style);
LayoutInflater localInflater = getLayoutInflater().cloneInContext(contextThemeWrapper);
final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
ArrayList<String> arrayList= new ArrayList<>();
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(subreddit);
SettingsSubAdapter.showSubThemeEditor(arrayList, MainActivity.this, dialoglayout);
}
Expand Down Expand Up @@ -1146,7 +1154,7 @@ public void onPageSelected(int position) {

doSubSidebar(usedArray.get(position));

// ((SubmissionsView) getCurrentFragment()).doAdapter();
// ((SubmissionsView) getCurrentFragment()).doAdapter();
if (adapter.getCurrentFragment() != null) {
SubredditPosts p = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet;
if (p.offline) {
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/me/ccrama/redditslide/Activities/Settings.java
Expand Up @@ -11,6 +11,7 @@
import com.afollestad.materialdialogs.AlertDialogWrapper;
import com.rey.material.widget.Slider;

import me.ccrama.redditslide.Authentication;
import me.ccrama.redditslide.R;
import me.ccrama.redditslide.Reddit;
import me.ccrama.redditslide.Visuals.Palette;
Expand Down Expand Up @@ -187,13 +188,24 @@ public void onClick(View v) {
Settings.this.startActivity(inte);
}
});
findViewById(R.id.reddit_settings).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.comments).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Settings.this, SettingsReddit.class);
startActivity(i);
Intent inte = new Intent(Settings.this, SettingsComments.class);
Settings.this.startActivity(inte);
}
});
if(Authentication.isLoggedIn) {
findViewById(R.id.reddit_settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Settings.this, SettingsReddit.class);
startActivity(i);
}
});
} else {
findViewById(R.id.reddit_settings).setVisibility(View.GONE);
}

}

Expand Down
Expand Up @@ -965,6 +965,7 @@ public void onClick(View v) {
}
} else {
firstHolder.itemView.findViewById(R.id.innerSend).setVisibility(View.GONE);
firstHolder.itemView.findViewById(R.id.reply).setVisibility(View.GONE);

}

Expand Down
40 changes: 4 additions & 36 deletions app/src/main/java/me/ccrama/redditslide/Authentication.java
Expand Up @@ -18,7 +18,6 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -128,41 +127,16 @@ public void onClick(DialogInterface dialog, int which) {
} else {
final Credentials fcreds = Credentials.userlessApp(CLIENT_ID, UUID.randomUUID());
OAuthData authData = null;
if (reddit != null) {
try {

authData = reddit.getOAuthHelper().easyAuth(fcreds);
Authentication.name = "LOGGEDOUT";
mod = false;

} catch (Exception e) {
try {
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
new AlertDialogWrapper.Builder(context).setTitle(R.string.err_general)
.setMessage(R.string.err_no_connection)
.setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new UpdateToken(context).execute();
}
}).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Reddit.forceRestart(context);

}
}).show();
}
});
//TODO fail
} catch (Exception ignored) {
//whelp crap
}
}
try {
reddit.authenticate(authData);
Log.v("Slide", "REAUTH LOGGED IN");

} catch (Exception e) {
try {
((Activity) context).runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -193,7 +167,7 @@ public void onClick(DialogInterface dialog, int which) {


}
}


}
return null;
Expand All @@ -212,13 +186,6 @@ public VerifyCredentials(Context context) {

@Override
public void onPostExecute(Void voids) {
if (a.loader != null) {

String[] strings = StartupStrings.startupStrings(mContext);
a.loader.loading.setText(strings[new Random().nextInt(strings.length)]);

}


new SubredditStorage(mContext).execute(a);

Expand Down Expand Up @@ -281,6 +248,7 @@ protected Void doInBackground(String... subs) {
OAuthData authData = null;
try {
authData = reddit.getOAuthHelper().easyAuth(fcreds);
reddit.authenticate(authData);
Authentication.name = "LOGGEDOUT";
return null;

Expand Down
17 changes: 0 additions & 17 deletions app/src/main/java/me/ccrama/redditslide/Reddit.java
Expand Up @@ -37,7 +37,6 @@

import me.ccrama.redditslide.Activities.Internet;
import me.ccrama.redditslide.Activities.LoadingData;
import me.ccrama.redditslide.Activities.MainActivity;
import me.ccrama.redditslide.Notifications.NotificationJobScheduler;
import me.ccrama.redditslide.util.IabHelper;
import me.ccrama.redditslide.util.IabResult;
Expand Down Expand Up @@ -106,7 +105,6 @@ public class Reddit extends MultiDexApplication implements Application.ActivityL
private final List<Listener> listeners = new ArrayList<>();
private final Handler mBackgroundDelayHandler = new Handler();
public boolean active;
public LoadingData loader;
private ImageLoader defaultImageLoader;
private boolean closed = false;
public boolean mInBackground = true;
Expand Down Expand Up @@ -199,11 +197,9 @@ public void onActivityResumed(Activity activity) {
notifyOnBecameForeground();

if (hasDone && hasDone2) {
loader = null;

authentication.updateToken(activity);
} else if (authentication == null) {
loader = null;
authentication = new Authentication(this);


Expand Down Expand Up @@ -412,7 +408,6 @@ public void uncaughtException(Thread thread, Throwable t) {
Authentication.isLoggedIn = appRestart.getBoolean("loggedin", false);
Authentication.name = appRestart.getString("name", "");
active = true;
startMain();

}

Expand All @@ -439,19 +434,7 @@ public static ArrayList<String> stringToArray(String string) {
return f;
}

public void startMain() {
if (active) {
Intent i = new Intent(this, MainActivity.class);
Log.v(TAG, "starting new");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);

if (loader != null) {
loader.finish();
loader = null;
}
}
}

public void restart() {
isRestarting = true;
Expand Down
19 changes: 3 additions & 16 deletions app/src/main/java/me/ccrama/redditslide/SubredditStorage.java
Expand Up @@ -15,7 +15,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

import me.ccrama.redditslide.Activities.MultiredditOverview;
import me.ccrama.redditslide.Activities.Shortcut;
Expand Down Expand Up @@ -239,15 +238,7 @@ protected ArrayList<String> doInBackground(final Reddit... params) {

}
}
if (params[0].loader != null) {
params[0].loader.runOnUiThread(new Runnable() {
@Override
public void run() {
String[] strings = StartupStrings.startupStrings(mContext);
params[0].loader.loading.setText(strings[new Random().nextInt(strings.length)]);
}
});
}

test.addAll(sortNoValue(newValues));
if (test.contains("")) {
test.remove("");
Expand All @@ -260,10 +251,7 @@ public void run() {
// }

alphabeticalSubscriptions = sort(new ArrayList<>(test));
if (params[0].loader != null) {

params[0].startMain();
}
if (shortcut != null) {
shortcut.doShortcut();
}
Expand Down Expand Up @@ -305,6 +293,8 @@ public void run() {
for (String s : Arrays.asList("announcements", "Art", "AskReddit", "askscience", "aww", "blog", "books", "creepy", "dataisbeautiful", "DIY", "Documentaries", "EarthPorn", "explainlikeimfive", "Fitness", "food", "funny", "Futurology", "gadgets", "gaming", "GetMotivated", "gifs", "history", "IAmA", "InternetIsBeautiful", "Jokes", "LifeProTips", "listentothis", "mildlyinteresting", "movies", "Music", "news", "nosleep", "nottheonion", "OldSchoolCool", "personalfinance", "philosophy", "photoshopbattles", "pics", "science", "Showerthoughts", "space", "sports", "television", "tifu", "todayilearned", "TwoXChromosomes", "UpliftingNews", "videos", "worldnews", "WritingPrompts")) {
if (!test.contains(s)) {
newValues.add(s);
realSubs.add(s.toLowerCase());

}

}
Expand All @@ -324,10 +314,7 @@ public void run() {
}*/

alphabeticalSubscriptions = sort(new ArrayList<>(test));
if (params[0].loader != null) {

params[0].startMain();
}
if (shortcut != null) {
shortcut.doShortcut();
}
Expand Down
Expand Up @@ -201,6 +201,7 @@ private static void doHideObjects(View v, Boolean secondary) {
if (subreddit.isEmpty()) {
if (!SettingValues.actionBarVisible) {
v.findViewById(R.id.actionbar).setVisibility(View.GONE);
if(v.findViewById(R.id.placeholder_bottom) != null)
v.findViewById(R.id.placeholder_bottom).setVisibility(View.VISIBLE);
}

Expand Down
32 changes: 31 additions & 1 deletion app/src/main/res/layout/activity_settings.xml
Expand Up @@ -254,7 +254,37 @@
android:textSize="16sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/comments"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:selectableItemBackground"
android:orientation="horizontal"

android:paddingLeft="16dp"
android:paddingRight="16dp">

<ImageView
android:layout_width="56dp"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:src="@drawable/commentchange"
android:tint="?attr/tint"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"

android:text="@string/settings_title_comments"
android:textColor="?attr/font"
android:textSize="16sp"
android:textStyle="bold"/>
</LinearLayout>

</LinearLayout>



Expand Down

0 comments on commit 00c4381

Please sign in to comment.