mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Implement Deep Link to open reddit links directly in this app.
This commit is contained in:
parent
47515b87d0
commit
a2f301f75e
@ -73,7 +73,6 @@
|
||||
android:theme="@style/AppTheme.NoActionBarWithTransparentStatusBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@ -92,15 +91,42 @@
|
||||
<activity
|
||||
android:name=".ViewPostDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https"
|
||||
android:host="www.reddit.com"
|
||||
android:pathPattern="/r/..*/comments/..*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ViewSubredditDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https"
|
||||
android:host="www.reddit.com"
|
||||
android:pathPattern="/r/..*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ViewUserDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https"
|
||||
android:host="www.reddit.com"
|
||||
android:pathPattern="/user/..*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
@ -44,6 +44,8 @@ import retrofit2.Retrofit;
|
||||
public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
|
||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback {
|
||||
|
||||
static final String EXTRA_POST_TYPE = "EPT";
|
||||
|
||||
private static final String FETCH_USER_INFO_STATE = "FUIS";
|
||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||
|
||||
@ -138,6 +140,14 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
||||
if (savedInstanceState != null) {
|
||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||
} else {
|
||||
if(getIntent().hasExtra(EXTRA_POST_TYPE)) {
|
||||
if(getIntent().getExtras().getString(EXTRA_POST_TYPE).equals("popular")) {
|
||||
viewPager.setCurrentItem(1);
|
||||
} else {
|
||||
viewPager.setCurrentItem(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glide = Glide.with(this);
|
||||
|
@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@ -32,6 +33,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -62,6 +64,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
@State
|
||||
Post mPost;
|
||||
@State
|
||||
Uri postUri;
|
||||
@State
|
||||
boolean isLoadingMoreChildren = false;
|
||||
@State
|
||||
boolean isRefreshing = false;
|
||||
@ -122,13 +126,17 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
if(mPost == null) {
|
||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||
if(getIntent().getData() != null) {
|
||||
postUri = getIntent().getData();
|
||||
} else {
|
||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
if(mPost == null) {
|
||||
if(postUri == null && mPost == null) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
fetchPostAndCommentsById(getIntent().getExtras().getString(EXTRA_POST_ID));
|
||||
} else {
|
||||
} else if(mPost != null) {
|
||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||
mOauthRetrofit, mGlide, mSharedPreferences, mPost,
|
||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
||||
@ -162,6 +170,17 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
List<String> segments = postUri.getPathSegments();
|
||||
int commentIndex = segments.indexOf("comments");
|
||||
if(commentIndex >= 0 || commentIndex != segments.size() - 1) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
fetchPostAndCommentsById(segments.get(commentIndex + 1));
|
||||
} else {
|
||||
//Deep link error handling
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
if(getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
@ -26,6 +27,8 @@ import com.google.android.material.chip.Chip;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@ -63,6 +66,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
||||
@BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab;
|
||||
|
||||
private String subredditName;
|
||||
private Uri subredditUri;
|
||||
private boolean subscriptionReady = false;
|
||||
private boolean isInLazyMode = false;
|
||||
|
||||
@ -113,7 +117,26 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
if(getIntent().getData() != null) {
|
||||
subredditUri = getIntent().getData();
|
||||
List<String> segments = subredditUri.getPathSegments();
|
||||
int rIndex = segments.indexOf("r");
|
||||
if(rIndex >= 0 && rIndex < segments.size() - 1) {
|
||||
subredditName = segments.get(rIndex + 1);
|
||||
if(subredditName.equals("popular") || subredditName.equals("all")) {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
//Deep link error handling
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
}
|
||||
|
||||
String title = "r/" + subredditName;
|
||||
subredditNameTextView.setText(title);
|
||||
|
||||
|
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
@ -29,6 +30,8 @@ import com.google.android.material.chip.Chip;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@ -71,6 +74,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
private AppBarLayout.LayoutParams params;
|
||||
|
||||
private String userName;
|
||||
private Uri userUri;
|
||||
private boolean subscriptionReady = false;
|
||||
private boolean isInLazyMode = false;
|
||||
private int colorPrimary;
|
||||
@ -106,7 +110,20 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
userName = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
|
||||
if(getIntent().getData() != null) {
|
||||
userUri = getIntent().getData();
|
||||
List<String> segments = userUri.getPathSegments();
|
||||
int userIndex = segments.indexOf("user");
|
||||
if(userIndex >= 0 && userIndex < segments.size() - 1) {
|
||||
userName = segments.get(userIndex + 1);
|
||||
} else {
|
||||
//Deep link error handling
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
userName = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
|
||||
}
|
||||
|
||||
String title = "u/" + userName;
|
||||
userNameTextView.setText(title);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user