mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-05 13:37:33 +01:00
added deep link for twitter search, bug fix
This commit is contained in:
parent
3a51617180
commit
ce4ffa5d47
@ -30,7 +30,25 @@
|
||||
<activity
|
||||
android:name=".window.SearchPage"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme" />
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<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="*.twitter.com"
|
||||
android:pathPattern="\\/search"
|
||||
android:scheme="https" />
|
||||
<data
|
||||
android:host="*.twitter.com"
|
||||
android:pathPattern="\\/hashtag\\/..*"
|
||||
android:scheme="https" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".window.UserProfile"
|
||||
|
@ -113,13 +113,6 @@ public class MediaViewer extends AppCompatActivity implements OnImageClickListen
|
||||
break;
|
||||
|
||||
case VIDEO:
|
||||
videoWindow.setVisibility(VISIBLE);
|
||||
video = Uri.parse(link[0]);
|
||||
videoView.setMediaController(videoController);
|
||||
videoView.setOnPreparedListener(this);
|
||||
videoView.setVideoURI(video);
|
||||
break;
|
||||
|
||||
case VIDEO_STORAGE:
|
||||
videoWindow.setVisibility(VISIBLE);
|
||||
video = Uri.parse(link[0]);
|
||||
|
@ -1,11 +1,14 @@
|
||||
package org.nuclearfog.twidda.window;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@ -15,11 +18,13 @@ import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener;
|
||||
|
||||
import org.nuclearfog.twidda.BuildConfig;
|
||||
import org.nuclearfog.twidda.MainActivity;
|
||||
import org.nuclearfog.twidda.R;
|
||||
import org.nuclearfog.twidda.adapter.FragmentAdapter;
|
||||
import org.nuclearfog.twidda.adapter.FragmentAdapter.AdapterType;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static org.nuclearfog.twidda.window.TweetPopup.KEY_TWEETPOPUP_ADDITION;
|
||||
|
||||
|
||||
@ -30,7 +35,8 @@ public class SearchPage extends AppCompatActivity implements OnTabSelectedListen
|
||||
|
||||
private FragmentAdapter adapter;
|
||||
private ViewPager pager;
|
||||
private String search;
|
||||
private GlobalSettings settings;
|
||||
private String search = "";
|
||||
private int tabIndex = 0;
|
||||
|
||||
@Override
|
||||
@ -48,12 +54,16 @@ public class SearchPage extends AppCompatActivity implements OnTabSelectedListen
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
|
||||
Bundle param = getIntent().getExtras();
|
||||
Uri link = getIntent().getData();
|
||||
settings = GlobalSettings.getInstance(this);
|
||||
|
||||
if (param != null && param.containsKey(KEY_SEARCH)) {
|
||||
search = param.getString(KEY_SEARCH);
|
||||
} else if (link != null) {
|
||||
getSearchString(link);
|
||||
} else if (BuildConfig.DEBUG)
|
||||
throw new AssertionError();
|
||||
|
||||
GlobalSettings settings = GlobalSettings.getInstance(this);
|
||||
root.setBackgroundColor(settings.getBackgroundColor());
|
||||
tab.setSelectedTabIndicatorColor(settings.getHighlightColor());
|
||||
|
||||
@ -132,4 +142,26 @@ public class SearchPage extends AppCompatActivity implements OnTabSelectedListen
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
|
||||
private void getSearchString(@NonNull Uri link) {
|
||||
String path = link.getPath();
|
||||
String query = link.getQuery();
|
||||
|
||||
if (path != null) {
|
||||
if (path.startsWith("/hashtag/")) {
|
||||
search = '#' + path.substring(9);
|
||||
} else if (path.startsWith("/search")) {
|
||||
if (query != null && query.length() > 2) {
|
||||
search = query.substring(2).replace('+', ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (search.isEmpty() || !settings.getLogin()) {
|
||||
Toast.makeText(this, R.string.failed_open_link, LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@ -77,7 +78,7 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, O
|
||||
tweetID = param.getLong(KEY_TWEET_ID);
|
||||
username = param.getString(KEY_TWEET_NAME);
|
||||
} else if (link != null) {
|
||||
getTweet(link.getPath());
|
||||
getTweet(link);
|
||||
} else if (BuildConfig.DEBUG) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
@ -262,29 +263,25 @@ public class TweetDetail extends AppCompatActivity implements OnClickListener, O
|
||||
}
|
||||
|
||||
|
||||
private void getTweet(String link) {
|
||||
if (!settings.getLogin()) {
|
||||
private void getTweet(@NonNull Uri link) {
|
||||
String path = link.getPath() == null ? "" : link.getPath();
|
||||
Pattern linkPattern = Pattern.compile("/@?[\\w_]+/status/\\d{1,20}");
|
||||
Matcher linkMatch = linkPattern.matcher(path);
|
||||
|
||||
if (linkMatch.matches() && settings.getLogin()) {
|
||||
if (path.startsWith("/@"))
|
||||
path = path.substring(1);
|
||||
else
|
||||
path = '@' + path.substring(1);
|
||||
int end = path.indexOf('/');
|
||||
username = path.substring(0, end);
|
||||
path = path.substring(end + 8);
|
||||
tweetID = Long.parseLong(path);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.failed_open_link, LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else if (link != null) {
|
||||
Pattern linkPattern = Pattern.compile("/@?[\\w_]+/status/\\d{1,20}");
|
||||
Matcher linkMatch = linkPattern.matcher(link);
|
||||
if (linkMatch.matches()) {
|
||||
if (link.startsWith("/@"))
|
||||
link = link.substring(1);
|
||||
else
|
||||
link = '@' + link.substring(1);
|
||||
int end = link.indexOf('/');
|
||||
username = link.substring(0, end);
|
||||
link = link.substring(end + 8);
|
||||
tweetID = Long.parseLong(link);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.not_found, LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -117,4 +117,5 @@
|
||||
<string name="error_empty_port">Proxy port muss gesetzt werden!</string>
|
||||
<string name="error_empty_pass">Proxy Passort darf nicht leer sein!</string>
|
||||
<string name="video_preview_button">Videovorschau Button</string>
|
||||
<string name="failed_open_link">Fehler beim Öffnen des links!</string>
|
||||
</resources>
|
@ -117,4 +117,5 @@
|
||||
<string name="proxy_authentication">Proxy login</string>
|
||||
<string name="error_empty_port">Port must be set!</string>
|
||||
<string name="error_empty_pass">Proxy password should not be empty!</string>
|
||||
<string name="failed_open_link">Failed to open link!</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user