添加检索

This commit is contained in:
sifacai@outlook.com 2022-08-28 21:17:57 +08:00
parent f71699898e
commit 58f1c7d0f1
4 changed files with 83 additions and 11 deletions

1
.idea/misc.xml generated
View File

@ -8,6 +8,7 @@
<entry key="..\:/code/VlcJellyfin/app/src/main/res/drawable/popmenu_focus.xml" value="0.1555" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/drawable/shape_user_focus_vholder.xml" value="0.1555" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/layout/activity_detail.xml" value="0.14583333333333334" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/layout/activity_search.xml" value="0.14583333333333334" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/layout/activity_vlc_player.xml" value="0.286231884057971" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/layout/item_h.xml" value="0.16770833333333332" />
<entry key="..\:/code/VlcJellyfin/app/src/main/res/layout/item_v.xml" value="0.14583333333333334" />

View File

@ -116,7 +116,6 @@ public class JAdapter extends RecyclerView.Adapter {
@Override
public int getItemCount() {
int count = items.size();
Log.d(TAG, "getItemCount: 数据总数:" + count);
return count;
}

View File

@ -1,44 +1,103 @@
package org.sifacai.vlcjellyfin;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.owen.tvrecyclerview.widget.TvRecyclerView;
import com.owen.tvrecyclerview.widget.V7GridLayoutManager;
public class SearchActivity extends BaseActivity{
private TvRecyclerView mGridContiner = null;
private TvRecyclerView mGridContiner;
private JAdapter adapter;
private final int limit = 24;
private String BaseUrl;
private EditText searchTermEdit;
private ImageView searchBtn;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_collection);
setContentView(R.layout.activity_search);
if (Utils.UserId.equals("") || Utils.AccessToken.equals("")) {
finish();
}
ActionBar actionBar = getSupportActionBar();
if(null != actionBar){
ImageView acb = actionBar.getCustomView().findViewById(R.id.activeBar_searchBtn);
if(null != acb){
acb.setVisibility(View.GONE);
}
}
mGridContiner = findViewById(R.id.mGridView);
V7GridLayoutManager v7GridLayoutManager = new V7GridLayoutManager(this,6);
mGridContiner.setLayoutManager(v7GridLayoutManager);
mGridContiner.setItemAnimator(null); //防崩溃
adapter = new JAdapter(new JsonArray());
mGridContiner.setAdapter(adapter);
BaseUrl = "/Users/"+Utils.UserId+"/Items?";
BaseUrl += "Fields=PrimaryImageAspectRatio,CanDelete,BasicSyncInfo,MediaSourceCount";
BaseUrl += "&Recursive=true&EnableTotalRecordCount=false&ImageTypeLimit=1&IncludePeople=false";
BaseUrl += "&IncludeMedia=true&IncludeGenres=false&IncludeStudios=false&IncludeArtists=false";
BaseUrl += "&Limit="+limit;
searchTermEdit = findViewById(R.id.searchTermEdit);
searchBtn = findViewById(R.id.searchBtn);
searchBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String st = searchTermEdit.getText().toString().trim();
if(st.length()>0){
Search(st);
}
}
});
searchTermEdit.requestFocus();
}
private void Search(String searchTerm) {
String url = BaseUrl + "&searchTerm="+searchTerm+"&IncludeItemTypes=Movie";
String movieUrl = BaseUrl + "&searchTerm="+searchTerm+"&IncludeItemTypes=Movie";
String seriesUrl = BaseUrl + "&searchTerm="+searchTerm+"&IncludeItemTypes=Series";
String episodeUrl = BaseUrl + "&searchTerm="+searchTerm+"&IncludeItemTypes=Episode";
new Thread(new Runnable() {
@Override
public void run() {
showLoadingDialog("搜索中………………");
String movieStr = Utils.okhttpSend(movieUrl);
String seriesStr = Utils.okhttpSend(seriesUrl);
JsonObject moviejob = Utils.JsonToObj(movieStr,JsonObject.class);
JsonObject seriesjob = Utils.JsonToObj(seriesStr,JsonObject.class);
JsonArray movieItems = moviejob.get("Items").getAsJsonArray();
JsonArray seriesItems = seriesjob.get("Items").getAsJsonArray();
movieItems.addAll(seriesItems);
fillItems(movieItems);
dismissLoadingDialog();
}
}).start();
}
private void fillItems(JsonArray items){
mAA.runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.clearItems();
adapter.addItems(items);
}
});
}
}

View File

@ -7,13 +7,26 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="32dp"
android:padding="@dimen/padding_border"
android:orientation="horizontal" >
<EditText
android:id="@+id/tvSearchBtn"
android:layout_width="match_parent"
android:layout_height="32dp"
android:textSize="@dimen/title_size" />
android:id="@+id/searchTermEdit"
android:layout_width="600dp"
android:layout_height="match_parent"
android:background="@drawable/shape_user_focus"
android:focusable="true"
android:tooltipText="关键字"/>
<ImageView
android:id="@+id/searchBtn"
android:layout_width="100dp"
android:layout_height="match_parent"
android:focusable="true"
android:src="@drawable/ic_outline_search_48"
android:background="@drawable/shape_user_focus"
android:layout_marginLeft="@dimen/button_margin_left" />
</LinearLayout>
<org.sifacai.vlcjellyfin.JRecyclerView