Skip to content

Commit

Permalink
Merge cc1d50f into c457c69
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphRoy committed Jul 12, 2018
2 parents c457c69 + cc1d50f commit b3164f7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ protected void onCreate(Bundle savedInstanceState) {
//Toast.makeText(MyApp.getContext(),"called button",Toast.LENGTH_SHORT).show();
if (item.getItemId() == R.id.action_search) {
// start search activity
GlobalConfig.searchType = GlobalConfig.SearchType.web;
startActivity(new Intent(MainActivity.this, SearchActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.hold); // fade in animation

} else if (item.getItemId() == R.id.action_search_fav) {
// start search activity
GlobalConfig.searchType = GlobalConfig.SearchType.bookshelf;
startActivity(new Intent(MainActivity.this, SearchActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.hold); // fade in animation

Expand Down Expand Up @@ -217,6 +224,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
case FAV:
if (getSupportActionBar() != null)
getSupportActionBar().setTitle(getResources().getString(R.string.main_menu_fav));
getMenuInflater().inflate(R.menu.menu_fav, menu);
break;
case CONFIG:
if (getSupportActionBar() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ public boolean onLongClick(View v) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@ public boolean onLongClick(View v) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.mewx.wenku8.adapter.NovelItemAdapterUpdate;
import org.mewx.wenku8.global.GlobalConfig;
import org.mewx.wenku8.global.api.NovelItemInfoUpdate;
import org.mewx.wenku8.global.api.NovelItemList;
import org.mewx.wenku8.global.api.Wenku8API;
import org.mewx.wenku8.global.api.Wenku8Parser;
import org.mewx.wenku8.listener.MyItemClickListener;
Expand All @@ -38,6 +39,7 @@
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -300,42 +302,55 @@ private class AsyncGetSearchResultList extends AsyncTask<String, Integer, Intege
@Override
protected Integer doInBackground(String... params) {

// get search result by novel title
ContentValues cv = Wenku8API.searchNovelByNovelName(params[0], GlobalConfig.getCurrentLang());
byte[] tempListTitle = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if(tempListTitle == null) return -1;

// purify returned data
List<Integer> listResultList = new ArrayList<>(); // result list
try {
//Log.i("MewX", new String(tempListTitle, "UTF-8"));
Pattern p = Pattern.compile("aid=\'(.*)\'"); // match content between "aid=\'" and "\'"
Matcher m = p.matcher(new String(tempListTitle, "UTF-8"));
while (m.find())
listResultList.add(Integer.valueOf(m.group(1)));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

// get search result by author name
cv = Wenku8API.searchNovelByAuthorName(params[0], GlobalConfig.getCurrentLang());
byte[] tempListName = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if(tempListName == null) return -1;

// purify returned data
List<Integer> listResultList2 = new ArrayList<>(); // result list
try {
Log.i("MewX", new String(tempListName, "UTF-8"));
Pattern p = Pattern.compile("aid=\'(.*)\'"); // match content between "aid=\'" and "\'"
Matcher m = p.matcher(new String(tempListName, "UTF-8"));
while (m.find()) {
listResultList2.add(Integer.valueOf(m.group(1)));
Log.e("MewX", listResultList2.get(listResultList2.size()-1).toString());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();

switch(GlobalConfig.searchType) {
case web:
// get search result by novel title
ContentValues cv = Wenku8API.searchNovelByNovelName(params[0], GlobalConfig.getCurrentLang());
byte[] tempListTitle = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if(tempListTitle == null) return -1;

// purify returned data
try {
//Log.i("MewX", new String(tempListTitle, "UTF-8"));
Pattern p = Pattern.compile("aid=\'(.*)\'"); // match content between "aid=\'" and "\'"
Matcher m = p.matcher(new String(tempListTitle, "UTF-8"));
while (m.find())
listResultList.add(Integer.valueOf(m.group(1)));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

// get search result by author name
cv = Wenku8API.searchNovelByAuthorName(params[0], GlobalConfig.getCurrentLang());
byte[] tempListName = LightNetwork.LightHttpPostConnection(Wenku8API.BASE_URL, cv);
if(tempListName == null) return -1;

break;
case bookshelf:
List<NovelItemInfoUpdate> listNovelItemInfo = new ArrayList<>();
for(int aid : GlobalConfig.getLocalBookshelfList()) {
String xml = GlobalConfig.loadFullFileFromSaveFolder("intro", aid + "-intro.xml");
if (!xml.isEmpty()) {
NovelItemInfoUpdate niiu = NovelItemInfoUpdate.convertFromMeta(
Objects.requireNonNull(Wenku8Parser.parseNovelFullMeta(xml)));
if(niiu != null) {
listNovelItemInfo.add(niiu);
}
}
}
for(NovelItemInfoUpdate info : listNovelItemInfo) {
if(info.author.toLowerCase().contains(params[0].toLowerCase()) ||
info.title.toLowerCase().contains(params[0].toLowerCase())) {
listResultList.add(info.aid);
}
}
break;
}


// set migrate
listNovelItemAid = new ArrayList<>();
listNovelItemAid.addAll(listResultList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class GlobalConfig {
private static boolean FirstStoragePathStatus = true;
private static Wenku8API.LANG currentLang = Wenku8API.LANG.SC;
public static String pathPickedSave; // dir picker save path
public static SearchType searchType;

// static variables
private static ArrayList<String> searchHistory = null;
Expand All @@ -97,6 +98,11 @@ public static class ReadSavesV1 { // deprecated
public int wordId;
}

public enum SearchType {
web,
bookshelf,
}

public enum SettingItems {
version, // (int) 1
language,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_search_fav"
android:title="@string/action_search"
android:icon="@drawable/ic_search"
app:showAsAction="withText|ifRoom" />
</menu>

0 comments on commit b3164f7

Please sign in to comment.