This commit is contained in:
Thomas 2020-06-28 12:14:14 +02:00
parent 37d2e2f034
commit 943445807d
8 changed files with 119 additions and 6 deletions

View File

@ -53,7 +53,11 @@
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppThemeNoActionBar" android:theme="@style/AppThemeNoActionBar"
android:windowSoftInputMode="stateAlwaysHidden" /> android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name=".SearchActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" />
<receiver <receiver
android:name=".services.PeertubeUploadReceiver" android:name=".services.PeertubeUploadReceiver"
android:exported="false"> android:exported="false">

View File

@ -1,6 +1,7 @@
package app.fedilab.fedilabtube; package app.fedilab.fedilabtube;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -9,6 +10,7 @@ import android.view.MenuItem;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.AppBarConfiguration;
@ -49,6 +51,27 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) { public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu); getMenuInflater().inflate(R.menu.main_menu, menu);
MenuItem myActionMenuItem = menu.findItem( R.id.action_search);
SearchView searchView = (SearchView) myActionMenuItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
Bundle b = new Bundle();
b.putString("search", query.trim());
intent.putExtras(b);
startActivity(intent);
if( ! searchView.isIconified()) {
searchView.setIconified(true);
}
myActionMenuItem.collapseActionView();
return false;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
return true; return true;
} }
@ -58,6 +81,7 @@ public class MainActivity extends AppCompatActivity {
showRadioButtonDialog(); showRadioButtonDialog();
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View File

@ -0,0 +1,65 @@
package app.fedilab.fedilabtube;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.fragment.DisplayStatusFragment;
import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
import es.dmoral.toasty.Toasty;
public class SearchActivity extends AppCompatActivity implements OnRetrieveFeedsInterface {
private String search;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_result);
Bundle b = getIntent().getExtras();
if (b != null) {
search = b.getString("search");
} else {
Toasty.error(SearchActivity.this, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
}
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(search);
if (savedInstanceState == null) {
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
Bundle bundle = new Bundle();
bundle.putString("search_peertube", search);
displayStatusFragment.setArguments(bundle);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.container, displayStatusFragment).commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onRetrieveFeeds(APIResponse apiResponse) {
}
}

View File

@ -12,23 +12,23 @@ import app.fedilab.fedilabtube.interfaces.OnRetrieveFeedsInterface;
public class RetrievePeertubeSearchAsyncTask extends AsyncTask<Void, Void, Void> { public class RetrievePeertubeSearchAsyncTask extends AsyncTask<Void, Void, Void> {
private String query, instance; private String query, max_id;
private APIResponse apiResponse; private APIResponse apiResponse;
private OnRetrieveFeedsInterface listener; private OnRetrieveFeedsInterface listener;
private WeakReference<Context> contextReference; private WeakReference<Context> contextReference;
public RetrievePeertubeSearchAsyncTask(Context context, String instance, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) { public RetrievePeertubeSearchAsyncTask(Context context, String max_id, String query, OnRetrieveFeedsInterface onRetrieveFeedsInterface) {
this.contextReference = new WeakReference<>(context); this.contextReference = new WeakReference<>(context);
this.query = query; this.query = query;
this.listener = onRetrieveFeedsInterface; this.listener = onRetrieveFeedsInterface;
this.instance = instance; this.max_id = max_id;
} }
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
PeertubeAPI api = new PeertubeAPI(this.contextReference.get()); PeertubeAPI api = new PeertubeAPI(this.contextReference.get());
apiResponse = api.searchPeertube(instance, query); apiResponse = api.searchPeertube(query, max_id);
return null; return null;
} }

View File

@ -1747,9 +1747,11 @@ public class PeertubeAPI {
* @param query String search * @param query String search
* @return APIResponse * @return APIResponse
*/ */
public APIResponse searchPeertube(String instance, String query) { public APIResponse searchPeertube(String query, String max_id) {
HashMap<String, String> params = new HashMap<>(); HashMap<String, String> params = new HashMap<>();
params.put("count", "50"); params.put("count", "50");
if (max_id != null)
params.put("start", max_id);
if (query == null) if (query == null)
return null; return null;
try { try {

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>

View File

@ -1,6 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="always|collapseActionView"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="@string/search"/>
<item <item
android:id="@+id/action_change_instance" android:id="@+id/action_change_instance"
android:icon="@drawable/ic_baseline_track_changes_24" android:icon="@drawable/ic_baseline_track_changes_24"

View File

@ -112,5 +112,8 @@
<string name="unfollow_confirm">Voulez-vous vous désabonner de ce compte ?</string> <string name="unfollow_confirm">Voulez-vous vous désabonner de ce compte ?</string>
<string name="action_unfollow">Se désabonner</string> <string name="action_unfollow">Se désabonner</string>
<string name="action_follow">Suivre</string> <string name="action_follow">Suivre</string>
<string name="search">Chercher</string>
<string name="toast_error_search">Une erreur sest produite lors de la recherche!</string>
<string name="no_result">Aucun résultat !</string>
</resources> </resources>