diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index e2d067b..b6a28dc 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -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(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 4dac219..4e38be7 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -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);