mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 10:28:22 +01:00
Create LinkResolverActivity to resolve the reddit links instead of resolving them in different activities. Deep link error handling is still broken.
This commit is contained in:
parent
a2f301f75e
commit
f86f06ffe5
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@ -19,6 +19,18 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity android:name=".LinkResolverActivity">
|
||||
<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:host="www.reddit.com"
|
||||
android:scheme="https" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".SearchActivity"
|
||||
android:label="@string/search_activity_label"
|
||||
@ -73,6 +85,7 @@
|
||||
android:theme="@style/AppTheme.NoActionBarWithTransparentStatusBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@ -91,42 +104,15 @@
|
||||
<activity
|
||||
android:name=".ViewPostDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
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>
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".ViewSubredditDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
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>
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
||||
<activity
|
||||
android:name=".ViewUserDetailActivity"
|
||||
android:parentActivityName=".MainActivity"
|
||||
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>
|
||||
android:theme="@style/AppTheme.NoActionBarWithTranslucentWindow" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
@ -135,8 +121,7 @@
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths">
|
||||
</meta-data>
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
|
@ -0,0 +1,69 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LinkResolverActivity extends AppCompatActivity {
|
||||
|
||||
private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/*[\\w+]*/*";
|
||||
private static final String SUBREDDIT_PATTERN = "/r/\\w+/*";
|
||||
private static final String USER_PATTERN = "/user/\\w+/*";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Uri uri = getIntent().getData();
|
||||
String path = uri.getPath();
|
||||
if(path.endsWith("/")) {
|
||||
path = path.substring(0, path.length() - 1);
|
||||
}
|
||||
|
||||
if(path.matches(POST_PATTERN)) {
|
||||
List<String> segments = uri.getPathSegments();
|
||||
int commentsIndex = segments.lastIndexOf("comments");
|
||||
if(commentsIndex >=0 && commentsIndex < segments.size() - 1) {
|
||||
Intent intent = new Intent(this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1));
|
||||
startActivity(intent);
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
} else if(path.matches(SUBREDDIT_PATTERN)) {
|
||||
String subredditName = path.substring(3);
|
||||
if(subredditName.equals("popular") || subredditName.equals("all")) {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3));
|
||||
startActivity(intent);
|
||||
}
|
||||
} else if(path.matches(USER_PATTERN)) {
|
||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, path.substring(6));
|
||||
startActivity(intent);
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
private void deepLinkError(Uri uri) {
|
||||
//Deep link error handling
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
// add share action to menu list
|
||||
builder.addDefaultShareMenuItem();
|
||||
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(this, uri);
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -33,7 +32,6 @@ 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;
|
||||
@ -64,8 +62,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
@State
|
||||
Post mPost;
|
||||
@State
|
||||
Uri postUri;
|
||||
@State
|
||||
boolean isLoadingMoreChildren = false;
|
||||
@State
|
||||
boolean isRefreshing = false;
|
||||
@ -126,17 +122,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
orientation = getResources().getConfiguration().orientation;
|
||||
|
||||
if(mPost == null) {
|
||||
if(getIntent().getData() != null) {
|
||||
postUri = getIntent().getData();
|
||||
} else {
|
||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||
}
|
||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||
}
|
||||
|
||||
if(postUri == null && mPost == null) {
|
||||
if(mPost == null) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
fetchPostAndCommentsById(getIntent().getExtras().getString(EXTRA_POST_ID));
|
||||
} else if(mPost != null) {
|
||||
} else {
|
||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||
mOauthRetrofit, mGlide, mSharedPreferences, mPost,
|
||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
||||
@ -170,17 +162,6 @@ 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,7 +2,6 @@ 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;
|
||||
@ -27,8 +26,6 @@ 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;
|
||||
|
||||
@ -66,7 +63,6 @@ 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;
|
||||
|
||||
@ -117,26 +113,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
||||
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
String title = "r/" + subredditName;
|
||||
subredditNameTextView.setText(title);
|
||||
|
||||
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
@ -118,7 +119,13 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
||||
userName = segments.get(userIndex + 1);
|
||||
} else {
|
||||
//Deep link error handling
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
builder.addDefaultShareMenuItem();
|
||||
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(this, userUri);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
userName = getIntent().getExtras().getString(EXTRA_USER_NAME_KEY);
|
||||
|
Loading…
Reference in New Issue
Block a user