mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Modified help page drawer behaviour (#719)
* Fixed drawer tests in other languages * Restructured getResourceString
This commit is contained in:
parent
60c159ad91
commit
0346422cc7
@ -1,7 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<title>Help</title>
|
||||
<meta charset="UTF-8" />
|
||||
<title>REPLACE_menu_help</title>
|
||||
</head>
|
||||
</html>
|
||||
|
||||
<body>
|
||||
<h1 style="display:none;">REPLACE_menu_help</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -145,6 +145,7 @@ import static org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_POSITIONS;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_CURRENT_TAB;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_FILE_SEARCHED;
|
||||
import static org.kiwix.kiwixmobile.utils.Constants.TAG_KIWIX;
|
||||
import static org.kiwix.kiwixmobile.utils.LanguageUtils.getResourceString;
|
||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||
import static org.kiwix.kiwixmobile.utils.UpdateUtils.reformatProviderUrl;
|
||||
|
||||
@ -394,7 +395,7 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
});
|
||||
|
||||
documentSections = new ArrayList<>();
|
||||
tabDrawerAdapter = new TabDrawerAdapter(mWebViews);
|
||||
tabDrawerAdapter = new TabDrawerAdapter(mWebViews, getApplicationContext());
|
||||
tabDrawerLeft.setLayoutManager(new LinearLayoutManager(this));
|
||||
tabDrawerLeft.setAdapter(tabDrawerAdapter);
|
||||
tableDrawerRight.setLayoutManager(new LinearLayoutManager(this));
|
||||
@ -447,8 +448,17 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
documentParser = new DocumentParser(new DocumentParser.SectionsListener() {
|
||||
@Override
|
||||
public void sectionsLoaded(String title, List<DocumentSection> sections) {
|
||||
for (DocumentSection section : sections) {
|
||||
if(section.title.contains("REPLACE_")) {
|
||||
section.title = getResourceString(getApplicationContext(), section.title);
|
||||
}
|
||||
}
|
||||
documentSections.addAll(sections);
|
||||
tableDrawerAdapter.setTitle(title);
|
||||
if(title.contains("REPLACE_")) {
|
||||
tableDrawerAdapter.setTitle(getResourceString(getApplicationContext(), title));
|
||||
} else {
|
||||
tableDrawerAdapter.setTitle(title);
|
||||
}
|
||||
tableDrawerAdapter.setSections(documentSections);
|
||||
tableDrawerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
@ -34,15 +35,18 @@ import butterknife.ButterKnife;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.N;
|
||||
import static org.kiwix.kiwixmobile.utils.LanguageUtils.getResourceString;
|
||||
|
||||
public class TabDrawerAdapter extends RecyclerView.Adapter<TabDrawerAdapter.ViewHolder> {
|
||||
private TabClickListener listener;
|
||||
private List<KiwixWebView> webViews;
|
||||
private Context appContext;
|
||||
|
||||
private int selectedPosition = 0;
|
||||
|
||||
public TabDrawerAdapter(List<KiwixWebView> webViews) {
|
||||
public TabDrawerAdapter(List<KiwixWebView> webViews, Context appContext) {
|
||||
this.webViews = webViews;
|
||||
this.appContext = appContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,7 +58,11 @@ public class TabDrawerAdapter extends RecyclerView.Adapter<TabDrawerAdapter.View
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
KiwixWebView webView = webViews.get(position);
|
||||
holder.title.setText(stripHtml(webView.getTitle()));
|
||||
String webViewTitle = stripHtml(webView.getTitle());
|
||||
if(webViewTitle.contains("REPLACE_")) {
|
||||
webViewTitle = getResourceString(appContext, webViewTitle);
|
||||
}
|
||||
holder.title.setText(webViewTitle);
|
||||
holder.exit.setOnClickListener(v -> listener.onCloseTab(v, position));
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
listener.onSelectTab(v, position);
|
||||
|
@ -341,4 +341,21 @@ public class LanguageUtils {
|
||||
return mLanguageName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getResourceString(Context appContext, String str){
|
||||
String resourceName = str;
|
||||
if(resourceName.contains("REPLACE_")) {
|
||||
resourceName = resourceName.replace("REPLACE_", "");
|
||||
}
|
||||
int resourceId = appContext.getResources()
|
||||
.getIdentifier(
|
||||
resourceName,
|
||||
"string",
|
||||
appContext.getPackageName()
|
||||
);
|
||||
String resourceString = appContext.getResources().getString(resourceId);
|
||||
return resourceString != null ? resourceString : str;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user