Fix issue #40 - Allow search to resolve peertube links

This commit is contained in:
Thomas 2020-11-07 10:38:30 +01:00
parent 4c1e466866
commit 14f0a47f52
2 changed files with 15 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -35,6 +36,7 @@ import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.kobakei.ratethisapp.RateThisApp;
@ -45,9 +47,12 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
import app.fedilab.fedilabtube.client.data.AccountData.Account;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.Error;
import app.fedilab.fedilabtube.client.entities.OauthParams;
import app.fedilab.fedilabtube.client.entities.PeertubeInformation;
@ -61,6 +66,7 @@ import app.fedilab.fedilabtube.helper.Helper;
import app.fedilab.fedilabtube.services.RetrieveInfoService;
import app.fedilab.fedilabtube.sqlite.AccountDAO;
import app.fedilab.fedilabtube.sqlite.Sqlite;
import app.fedilab.fedilabtube.viewmodel.SearchVM;
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
import es.dmoral.toasty.Toasty;
@ -293,6 +299,15 @@ public class MainActivity extends AppCompatActivity {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Pattern link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
Matcher matcherLink = link.matcher(query.trim());
if (matcherLink.find()) {
Intent intent = new Intent(MainActivity.this, PeertubeActivity.class);
intent.setData(Uri.parse(query.trim()));
startActivity(intent);
myActionMenuItem.collapseActionView();
return false;
}
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
Bundle b = new Bundle();
String search = query.trim();

View File

@ -427,11 +427,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private void manageVIewVideos(APIResponse apiResponse) {
if (apiResponse == null || apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0) {
playVideo();
if(urlIntent != null) {
Helper.forwardToAnotherApp(PeertubeActivity.this, urlIntent);
urlIntent = null;
finish();
}
return;
}
peertube = apiResponse.getPeertubes().get(0);