Skip to content

Commit

Permalink
added menu item to jump to specific page; added view for input text
Browse files Browse the repository at this point in the history
  • Loading branch information
PureDark committed Oct 15, 2016
1 parent 28fd8e5 commit 0c2c9ed
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<application
android:name=".HViewerApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
Expand Down
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HViewerApplication extends SwipeBackApplication {
* 是否开启日志输出,在Debug状态下开启,
* 在Release状态下关闭以提示程序性能
*/
public final static boolean DEBUG = false;
public final static boolean DEBUG = true;

// 全局变量,用于跨Activity传递复杂对象的引用
public static Object temp, temp2, temp3, temp4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public void onResponse(Call call, Response response) throws IOException {
final ResponseBody body = response.body();
try {
if (!response.isSuccessful()) {
Log.d("MyOkHttpNetworkFetcher", "request.headers():" + request.headers());
handleException(
call,
new IOException("Unexpected HTTP code " + response),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ public void setPictureViewerActivity(PictureViewerActivity activity) {
}

private boolean commentEnabled() {
return site.galleryRule.commentItem != null &&
return (site.galleryRule.commentRule != null &&
site.galleryRule.commentRule.item != null &&
site.galleryRule.commentRule.author != null&&
site.galleryRule.commentRule.content != null)
||(site.galleryRule.commentItem != null &&
site.galleryRule.commentAuthor != null &&
site.galleryRule.commentContent != null;
site.galleryRule.commentContent != null);
}

private void refreshDescription(String url) {
Expand Down
105 changes: 66 additions & 39 deletions app/src/main/java/ml/puredark/hviewer/ui/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.dpizarro.autolabel.library.AutoLabelUI;
import com.gc.materialdesign.views.ButtonFlat;
import com.google.gson.Gson;
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
import com.h6ah4i.android.widget.advrecyclerview.expandable.RecyclerViewExpandableItemManager;
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
import com.miguelcatalan.materialsearchview.MaterialSearchView;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
Expand All @@ -58,6 +63,7 @@
import ml.puredark.hviewer.dataholders.FavorTagHolder;
import ml.puredark.hviewer.dataholders.SiteHolder;
import ml.puredark.hviewer.dataholders.SiteTagHolder;
import ml.puredark.hviewer.helpers.ExampleSites;
import ml.puredark.hviewer.helpers.MDStatusBarCompat;
import ml.puredark.hviewer.ui.adapters.CategoryAdapter;
import ml.puredark.hviewer.ui.adapters.MySearchAdapter;
Expand All @@ -69,7 +75,10 @@
import ml.puredark.hviewer.ui.dataproviders.ListDataProvider;
import ml.puredark.hviewer.ui.fragments.CollectionFragment;
import ml.puredark.hviewer.ui.fragments.MyFragment;
import ml.puredark.hviewer.utils.DensityUtil;
import ml.puredark.hviewer.utils.SimpleFileUtil;

import static android.R.attr.padding;
import static ml.puredark.hviewer.HViewerApplication.searchHistoryHolder;
import static ml.puredark.hviewer.HViewerApplication.temp;

Expand Down Expand Up @@ -182,12 +191,12 @@ private void initNavSites() {
final List<Pair<SiteGroup, List<Site>>> siteGroups = siteHolder.getSites();

// 测试新站点用
// List<Site> sites = ExampleSites.get();
// siteGroups.add(0, new Pair<>(new SiteGroup(1, "TEST"), new ArrayList<>()));
List<Site> sites = ExampleSites.get();
siteGroups.add(0, new Pair<>(new SiteGroup(1, "TEST"), new ArrayList<>()));
// siteGroups.get(0).second.addAll(sites);
// siteGroups.get(0).second.add(sites.get(sites.size()-2));
// siteGroups.get(0).second.add(sites.get(sites.size()-1));
// SimpleFileUtil.writeString("/sdcard/sites.txt", new Gson().toJson(sites.get(sites.size()-1)), "utf-8");
siteGroups.get(0).second.add(sites.get(sites.size()-1));
SimpleFileUtil.writeString("/sdcard/sites.txt", new Gson().toJson(sites.get(sites.size()-1)), "utf-8");

ExpandableDataProvider dataProvider = new ExpandableDataProvider(siteGroups);
mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(null);
Expand Down Expand Up @@ -232,10 +241,11 @@ private void initNavSites() {
public void onGroupClick(View v, int groupPosition) {
// 点击分类(如果是新建按钮则创建,否则展开)
if (groupPosition == siteAdapter.getGroupCount() - 1) {
final EditText inputGroupTitle = new EditText(MainActivity.this);
View view = getLayoutInflater().inflate(R.layout.view_input_text, null);
MaterialEditText inputGroupTitle = (MaterialEditText) view.findViewById(R.id.input_text);
new AlertDialog.Builder(MainActivity.this)
.setTitle("新建组名")
.setView(inputGroupTitle)
.setView(view)
.setNegativeButton("取消", null)
.setPositiveButton("确定", (dialog, which) -> {
String title = inputGroupTitle.getText().toString();
Expand All @@ -259,36 +269,28 @@ public boolean onGroupLongClick(View v, final int groupPosition) {
final SiteGroup group = siteAdapter.getDataProvider().getGroupItem(groupPosition);
new AlertDialog.Builder(MainActivity.this)
.setTitle("操作")
.setItems(new String[]{"重命名", "删除"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
final EditText inputGroupTitle = new EditText(MainActivity.this);
inputGroupTitle.setText(group.title);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("重命名组").setView(inputGroupTitle)
.setNegativeButton("取消", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String title = inputGroupTitle.getText().toString();
group.title = title;
siteHolder.updateSiteGroup(group);
siteAdapter.notifyDataSetChanged();
}
}).show();
} else if (i == 1) {
new AlertDialog.Builder(MainActivity.this).setTitle("是否删除?")
.setMessage("删除后将无法恢复")
.setNegativeButton("取消", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
siteHolder.deleteSiteGroup(group);
siteAdapter.getDataProvider().removeGroupItem(groupPosition);
siteAdapter.notifyDataSetChanged();
}
}).show();
}
.setItems(new String[]{"重命名", "删除"}, (dialogInterface, i) -> {
if (i == 0) {
View view = getLayoutInflater().inflate(R.layout.view_input_text, null);
MaterialEditText inputGroupTitle = (MaterialEditText) view.findViewById(R.id.input_text);
new AlertDialog.Builder(MainActivity.this).setTitle("重命名组")
.setView(view)
.setNegativeButton("取消", null)
.setPositiveButton("确定", (dialog, which) -> {
String title = inputGroupTitle.getText().toString();
group.title = title;
siteHolder.updateSiteGroup(group);
siteAdapter.notifyDataSetChanged();
}).show();
} else if (i == 1) {
new AlertDialog.Builder(MainActivity.this).setTitle("是否删除?")
.setMessage("删除后将无法恢复")
.setNegativeButton("取消", null)
.setPositiveButton("确定", (dialog, which) -> {
siteHolder.deleteSiteGroup(group);
siteAdapter.getDataProvider().removeGroupItem(groupPosition);
siteAdapter.notifyDataSetChanged();
}).show();
}
})
.setNegativeButton("取消", null)
Expand Down Expand Up @@ -467,13 +469,17 @@ public void onStateChanged(AppBarLayout appBarLayout, State state) {
if (state == State.COLLAPSED) {
if (size > 1)
toolbar.getMenu().getItem(size - 1).setVisible(true);
if (size > 2)
toolbar.getMenu().getItem(size - 2).setVisible(true);
if (searchView.isSearchOpen()) {
searchView.animate().alpha(1f).setDuration(300);
showBottomSheet(behavior, true);
}
} else {
if (size > 1)
toolbar.getMenu().getItem(size - 1).setVisible(false);
if (size > 2)
toolbar.getMenu().getItem(size - 2).setVisible(false);
if (searchView.isSearchOpen()) {
searchView.animate().alpha(0f).setDuration(300);
showBottomSheet(behavior, false);
Expand Down Expand Up @@ -697,13 +703,14 @@ private void favorTags() {
}

private void addTags(int sid, AbstractTagHolder tagHolder) {
final EditText inputGroupTitle = new EditText(MainActivity.this);
View view = getLayoutInflater().inflate(R.layout.view_input_text, null);
MaterialEditText inputTagTitle = (MaterialEditText) view.findViewById(R.id.input_text);
new AlertDialog.Builder(MainActivity.this)
.setTitle("TAG名")
.setView(inputGroupTitle)
.setView(view)
.setNegativeButton("取消", null)
.setPositiveButton("确定", (dialog, which) -> {
String title = inputGroupTitle.getText().toString();
String title = inputTagTitle.getText().toString();
Tag tag = new Tag(0, title);
tagHolder.addTag(sid, tag);
refreshTags(sid, tagHolder);
Expand Down Expand Up @@ -807,6 +814,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_favourite:
intent = new Intent(MainActivity.this, FavouriteActivity.class);
break;
case R.id.action_jump_to_page:
View view = getLayoutInflater().inflate(R.layout.view_input_text, null);
MaterialEditText inputJumpToPage = (MaterialEditText) view.findViewById(R.id.input_text);
inputJumpToPage.setInputType(InputType.TYPE_CLASS_NUMBER);
new AlertDialog.Builder(MainActivity.this)
.setTitle("跳转到第几页?")
.setView(view)
.setNegativeButton("取消", null)
.setPositiveButton("确定", (dialog, which) -> {
String pageStr = inputJumpToPage.getText().toString();
int page = 0;
try{
page = Integer.parseInt(pageStr);
}catch (Exception e){
page = 0;
}
if(currFragment!=null)
currFragment.onJumpToPage(page);
}).show();
return true;
case R.id.action_search:
search();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void onSuccess(String contentType, Object result) {
new Thread(() -> {
FileHelper.createFileIfNotExist("temp", DownloadManager.getDownloadPath());
final boolean success = QRCodeUtil.createQRImage(url, 300, 300,
BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),
BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher),
FileHelper.getFileOutputSteam("temp", DownloadManager.getDownloadPath()));

runOnUiThread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ public boolean onItemLongClick(View v, int position) {
private void getCollections(String keyword, final int page) {
if (onePage && page > startPage) {
// 如果URL中根本没有page参数的位置,则肯定只有1页,无需多加载一次
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
rvCollection.setPullLoadMoreCompleted();
}
});
getActivity().runOnUiThread(() -> rvCollection.setPullLoadMoreCompleted());
return;
}
this.keyword = keyword;
Expand Down Expand Up @@ -301,6 +296,13 @@ public void onLoadUrl(String url) {
}
}

@Override
public void onJumpToPage(int page) {
rvCollection.setRefreshing(true);
adapter.getDataProvider().clear();
getCollections(keyword, page);
}

@Override
public void setRecyclerViewToList() {
adapter.setIsGrid(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class MyFragment extends Fragment {

public abstract void onLoadUrl(String url);

public abstract void onJumpToPage(int page);

public abstract void setRecyclerViewToList();

public abstract void setRecyclerViewToGrid();
Expand Down
Binary file removed app/src/main/res/drawable/ic_launcher.png
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_collection_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
android:layout_width="0dp"
android:layout_height="@dimen/tool_bar_height"
android:layout_weight="1"
android:gravity="center"
android:gravity="center_vertical"
android:text=""
android:textAppearance="@style/ActionBar.Title" />

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/view_input_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/half_padding">
<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
style="@style/EditTextAddSite"/>
</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/menu/search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
android:orderInCategory="3"
android:title="收藏夹"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_jump_to_page"
android:icon="@drawable/selector_gallery"
android:orderInCategory="4"
android:title="跳转到页数"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/action_search"
android:icon="@drawable/selector_search"
Expand Down
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0c2c9ed

Please sign in to comment.