Browse Source

auto-cookie-detection

legacy
Austin Huang 4 years ago
parent
commit
582b651d79
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 4
      app/src/main/java/awais/instagrabber/MainHelper.java
  2. 14
      app/src/main/java/awais/instagrabber/activities/Login.java
  3. 11
      app/src/main/java/awais/instagrabber/activities/Main.java
  4. 11
      app/src/main/res/drawable-anydpi/ic_info.xml
  5. BIN
      app/src/main/res/drawable-hdpi/ic_info.png
  6. BIN
      app/src/main/res/drawable-mdpi/ic_info.png
  7. BIN
      app/src/main/res/drawable-xhdpi/ic_info.png
  8. BIN
      app/src/main/res/drawable-xxhdpi/ic_info.png
  9. 2
      app/src/main/res/values/strings.xml

4
app/src/main/java/awais/instagrabber/MainHelper.java

@ -261,7 +261,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
private RecyclerLazyLoader feedLazyLoader, discoverLazyLoader;
private DiscoverAdapter discoverAdapter;
public SimpleExoPlayer currentFeedPlayer; // hack for remix drawer layout
final boolean isLoggedIn = !Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE));
public final boolean isLoggedIn = !Utils.isEmpty(Utils.settingsHelper.getString(Constants.COOKIE));
public MainHelper(@NonNull final Main main) {
stopCurrentExecutor();
@ -624,6 +624,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
}
main.mainBinding.appBarLayout.setExpanded(true, true);
main.mainBinding.privatePage.setVisibility(View.GONE);
main.mainBinding.privatePage2.setTextSize(28);
main.mainBinding.mainProfileImage.setImageBitmap(null);
main.mainBinding.mainHashtagImage.setImageBitmap(null);
main.mainBinding.mainLocationImage.setImageBitmap(null);
@ -928,7 +929,6 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener {
if (!profileModel.isReallyPrivate()) {
main.mainBinding.mainFollowing.setClickable(true);
main.mainBinding.mainFollowers.setClickable(true);
main.mainBinding.privatePage.setVisibility(View.GONE);
if (isLoggedIn) {
final View.OnClickListener followClickListener = v -> main.startActivity(new Intent(main, FollowViewer.class)

14
app/src/main/java/awais/instagrabber/activities/Login.java

@ -1,6 +1,7 @@
package awais.instagrabber.activities;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
@ -31,10 +32,19 @@ public final class Login extends BaseLanguageActivity implements View.OnClickLis
@Override
public void onPageFinished(final WebView view, final String url) {
webViewUrl = url;
final String mainCookie = Utils.getCookie(url);
if (!mainCookie.contains("; ds_user_id=")) ready = true;
else if (mainCookie.contains("; ds_user_id=") && ready) {
Utils.setupCookies(mainCookie);
settingsHelper.putString(Constants.COOKIE, mainCookie);
Toast.makeText(getApplicationContext(), R.string.login_success_loading_cookies, Toast.LENGTH_SHORT).show();
finish();
}
}
};
private final WebChromeClient webChromeClient = new WebChromeClient();
private String webViewUrl, defaultUserAgent;
private boolean ready = false;
private ActivityLoginBinding loginBinding;
@Override
@ -62,7 +72,9 @@ public final class Login extends BaseLanguageActivity implements View.OnClickLis
Utils.setupCookies(mainCookie);
settingsHelper.putString(Constants.COOKIE, mainCookie);
Toast.makeText(this, R.string.login_success_loading_cookies, Toast.LENGTH_SHORT).show();
finish();
Intent intent = new Intent(getApplicationContext(), Main.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
}

11
app/src/main/java/awais/instagrabber/activities/Main.java

@ -230,8 +230,13 @@ public final class Main extends BaseLanguageActivity {
mainBinding.mainLocationImage.setEnabled(false);
final boolean isQueryNull = userQuery == null;
if (isQueryNull) allItems.clear();
if (BuildConfig.DEBUG && isQueryNull) userQuery = "@austinhuang.me";
if (isQueryNull) {
allItems.clear();
mainBinding.privatePage1.setImageResource(R.drawable.ic_info);
mainBinding.privatePage2.setTextSize(20);
mainBinding.privatePage2.setText(mainHelper.isLoggedIn ? R.string.no_acc_logged_in : R.string.no_acc);
mainBinding.privatePage.setVisibility(View.VISIBLE);
}
if (!mainBinding.swipeRefreshLayout.isRefreshing() && userQuery != null) mainHelper.onRefresh();
mainHelper.onIntent(getIntent());
@ -327,7 +332,7 @@ public final class Main extends BaseLanguageActivity {
searchView.setQueryHint(getResources().getString(R.string.action_search));
searchView.setSuggestionsAdapter(suggestionAdapter);
searchView.setOnSearchClickListener(v -> {
searchView.setQuery((cookieModel != null && userQuery.equals("@"+cookieModel.getUsername())) ? "" : userQuery, false);
searchView.setQuery((cookieModel != null && userQuery != null && userQuery.equals("@"+cookieModel.getUsername())) ? "" : userQuery, false);
menu.findItem(R.id.action_about).setVisible(false);
menu.findItem(R.id.action_settings).setVisible(false);
menu.findItem(R.id.action_dms).setVisible(false);

11
app/src/main/res/drawable-anydpi/ic_info.xml

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:alpha="0.8"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>

BIN
app/src/main/res/drawable-hdpi/ic_info.png

After

Width: 36  |  Height: 36  |  Size: 451 B

BIN
app/src/main/res/drawable-mdpi/ic_info.png

After

Width: 24  |  Height: 24  |  Size: 253 B

BIN
app/src/main/res/drawable-xhdpi/ic_info.png

After

Width: 48  |  Height: 48  |  Size: 597 B

BIN
app/src/main/res/drawable-xxhdpi/ic_info.png

After

Width: 72  |  Height: 72  |  Size: 811 B

2
app/src/main/res/values/strings.xml

@ -68,6 +68,8 @@
<string name="votef_story_poll">Vote successful!</string>
<string name="voted_story_poll">You have already voted!</string>
<string name="priv_acc">This Account is Private</string>
<string name="no_acc">You can log in via Settings on the bottom-right corner. Or, you can view public accounts without login!</string>
<string name="no_acc_logged_in">You can swipe left/right for explore/feed, or search something below!</string>
<string name="empty_acc">This Account has No Posts</string>
<string name="empty_list">No Such Posts!</string>
<string name="curr_version">Current version: v%s</string>

Loading…
Cancel
Save