Skip to content

Commit

Permalink
Fix recycler view direction problem
Browse files Browse the repository at this point in the history
  • Loading branch information
lmovse committed Oct 6, 2018
1 parent 50ce100 commit b6d2900
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ captures/
# Intellij
*.iml
.idea/
app/release/

# Keystore files
*.jks
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- 复制翻译:无需打开 APP,无需输入单词,长按文本,点击复制,你想要的便出现在你面前
- 快速翻译:一触即达,方便你的生活
- 夜间模式:在最深的夜里给还在奋斗的你最温暖的翻译体验
- 多源翻译:有道,金山,百度,扇贝,译云,给你最多种的选择
- 多源翻译:谷歌,有道,金山,百度,扇贝,译云,给你最多种的选择

点击下载,安装,惊喜为你而来。

Expand All @@ -20,4 +20,5 @@
- [新增] 一键删除历史记录
- [修复] 切换到任务栏时的主题着色不一致
- [修复] 切换到译云源时查询原文会改变
- [修复] 分割线显示问题
- [优化] 扇贝源只支持英文单词译中的提示
23 changes: 11 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ android {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/library-1.0.19.jar')
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.android.support:cardview-v7:28.0.0'
compile 'com.android.support:design:28.0.0'
compile 'com.android.support:support-v4:28.0.0'
compile 'com.android.support:support-vector-drawable:28.0.0'
testCompile 'junit:junit:4.12'
implementation files('libs/library-1.0.19.jar')
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'io.apisense:rhino-android:1.0'
implementation 'com.google.code.gson:gson:2.8.5'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
Expand All @@ -25,7 +26,6 @@
import com.example.jooff.shuyi.data.AppDbRepository;
import com.example.jooff.shuyi.data.entity.Collect;
import com.example.jooff.shuyi.translate.main.MainTransView;
import com.example.jooff.shuyi.util.DividerItemDecoration;

import java.util.ArrayList;

Expand Down Expand Up @@ -70,7 +70,7 @@ public void initView() {
recCollect.setAdapter(mAdapter);
recCollect.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recCollect.setNestedScrollingEnabled(false);
recCollect.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST));
recCollect.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(new HistoryRvCallback());
mItemTouchHelper.attachToRecyclerView(recCollect);
mPresenter.initTheme();
Expand Down Expand Up @@ -196,12 +196,9 @@ public void onBindViewHolder(final CollectRvAdapter.collectViewHolder holder, in
holder.textOriginal.setText(item.getOriginal());
holder.textResult.setText(item.getResult());
if (onItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = holder.getLayoutPosition();
onItemClickListener.onItemClick(holder.itemView, pos);
}
holder.itemView.setOnClickListener(view -> {
int pos = holder.getLayoutPosition();
onItemClickListener.onItemClick(holder.itemView, pos);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void getTrans(int tranFrom, String transUrl, AppDbSource.TranslateCallbac
break;
case R.id.source_youdao:
RemoteJsonSource.getInstance().getTrans(TransSource.FROM_YOUDAO, transUrl, callback);
break;
case R.id.source_google:
RemoteJsonSource.getInstance().getTrans(TransSource.FROM_GOOGLE, transUrl, callback);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LocalDbOpenHelper extends SQLiteOpenHelper {
+ AppDbSchema.HistoryTable._ID + " integer" + " primary key autoincrement,"
+ AppDbSchema.HistoryTable.ORIGINAL + " text,"
+ AppDbSchema.HistoryTable.RESULT + " text, "
+ AppDbSchema.HistoryTable.COLLECTED + "tinyint unsigned default 0" + ")";
+ AppDbSchema.HistoryTable.COLLECTED + " tinyint unsigned default 0" + ")";

private static final String CREATE_COLLECT = "CREATE TABLE "
+ AppDbSchema.CollectTable.TABLE_NAME + " ("
Expand All @@ -48,7 +48,7 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVers
if (oldVersion == 1) {
sqLiteDatabase.execSQL("ALTER TABLE "
+ AppDbSchema.HistoryTable.TABLE_NAME + " ADD "
+ AppDbSchema.HistoryTable.COLLECTED + "tinyint unsigned default 0 ");
+ AppDbSchema.HistoryTable.COLLECTED + " tinyint unsigned default 0 ");
sqLiteDatabase.execSQL("CREATE TABLE "
+ AppDbSchema.CollectTable.TABLE_NAME + "("
+ AppDbSchema.CollectTable._ID + " integer" + " primary key autoincrement" + ", "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
Expand All @@ -26,7 +27,6 @@
import com.example.jooff.shuyi.data.AppDbRepository;
import com.example.jooff.shuyi.data.entity.History;
import com.example.jooff.shuyi.translate.main.MainTransView;
import com.example.jooff.shuyi.util.DividerItemDecoration;

import java.util.ArrayList;

Expand Down Expand Up @@ -68,11 +68,11 @@ public void onStart() {

@Override
public void initView() {
mAdapter = new HistoryRvAdapter(new ArrayList<History>(0), mListener);
mAdapter = new HistoryRvAdapter(new ArrayList<>(0), mListener);
recHistory.setAdapter(mAdapter);
recHistory.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recHistory.setNestedScrollingEnabled(false);
recHistory.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL_LIST));
recHistory.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(new HistoryRvCallback());
mItemTouchHelper.attachToRecyclerView(recHistory);
mPresenter.initTheme();
Expand Down Expand Up @@ -169,7 +169,7 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
} else {
// 拖动时有系统自己完成
// 拖动时由系统自己完成
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
Expand Down Expand Up @@ -205,12 +205,9 @@ public void onBindViewHolder(final HistoryRvAdapter.historyViewHolder holder, in
holder.collect.setTag(true);
}
if (onItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = holder.getLayoutPosition();
onItemClickListener.onItemClick(holder.itemView, pos);
}
holder.itemView.setOnClickListener(view -> {
int pos = holder.getLayoutPosition();
onItemClickListener.onItemClick(holder.itemView, pos);
});
}
}
Expand All @@ -232,10 +229,13 @@ public void refreshItems(ArrayList<History> items) {
}

class historyViewHolder extends RecyclerView.ViewHolder {

@BindView(R.id.item_original)
TextView textOriginal;

@BindView(R.id.item_result)
TextView textResult;

@BindView(R.id.collcect)
ImageView collect;

Expand All @@ -259,7 +259,6 @@ public void show(ImageView collect) {
ButterKnife.bind(this, itemView);
}
}

}

public interface OnItemClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public HistoryPresenter(AppDbSource.HistoryDbSource historyDbSource, HistoryCont

@Override
public void loadData() {
ArrayList<History> historys = mHistoryDbSource.getHistories();
if (!historys.isEmpty()) {
mHistoryView.showHistory(historys);
ArrayList<History> histories = mHistoryDbSource.getHistories();
if (!histories.isEmpty()) {
mHistoryView.showHistory(histories);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void showConfirmFinish() {

@Override
public void onSuccess(int transFrom, String original) {
if (transFrom == TransSource.FROM_HISTORY) {
if (transFrom == TransSource.FROM_HISTORY || transFrom == TransSource.FROM_COLLECT) {
mEditText.setText(original);
}
mProgressBar.setVisibility(View.GONE);
Expand Down

This file was deleted.

Loading

0 comments on commit b6d2900

Please sign in to comment.