Skip to content

Commit

Permalink
实现了文章翻页功能
Browse files Browse the repository at this point in the history
  • Loading branch information
reatiny committed Jul 2, 2019
1 parent 853a41c commit da7327d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
37 changes: 35 additions & 2 deletions app/src/main/java/xyz/somelou/rss/article/ArticleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -29,21 +30,24 @@
import xyz.somelou.rss.utils.IntentUtil;
import xyz.somelou.rss.utils.RSSUtil;

public class ArticleActivity extends AppCompatActivity {
public class ArticleActivity extends AppCompatActivity implements View.OnClickListener {
private Toolbar mToolbar;
private RSSItemBean mItemBean;
private FavorRSSItemDALImpl favorRSSItemDAL;
protected static final float FLIP_DISTANCE = 50;
SmsManager smsManager=SmsManager.getDefault();

private ImageButton mPreviousBtn;
private ImageButton mNextBtn;


TextView textView_title;
TextView textView_author;
TextView textView_date;
WebView textView_content;

private int articlePosition;
RSSUtil rssUtil;
GestureDetector mDetector;
ArrayList<RSSItemBean> list;

@Override
Expand Down Expand Up @@ -88,6 +92,11 @@ private void initViews() {
textView_content = findViewById(R.id.article_content);
textView_author = findViewById(R.id.subscription_name);

mPreviousBtn = (ImageButton) findViewById(R.id.previous_btn);
mPreviousBtn.setOnClickListener(this);
mNextBtn = (ImageButton) findViewById(R.id.next_btn);
mNextBtn.setOnClickListener(this);

textView_author.setText(list.get(articlePosition).getAuthor().toString());
//textView_content.setText(list.get(0).getDescription());
textView_date.setText(list.get(articlePosition).getPubDate().toString());
Expand Down Expand Up @@ -204,7 +213,31 @@ public boolean onMenuItemClick(MenuItem item) {
}


@Override
public void onClick(View v) {
if (v == mPreviousBtn) {
if(articlePosition<1){
Toast.makeText(ArticleActivity.this, "已经是第一篇", Toast.LENGTH_SHORT).show();
}else{
articlePosition--;
textView_author.setText(list.get(articlePosition).getAuthor().toString());
textView_date.setText(list.get(articlePosition).getPubDate().toString());
textView_title.setText(list.get(articlePosition).getTitle().toString());
textView_content.loadUrl(list.get(articlePosition).getUri());
}

} else if (v == mNextBtn) {
if(articlePosition>=list.size()-1){
Toast.makeText(ArticleActivity.this, "已经是最后一篇", Toast.LENGTH_SHORT).show();
}else{
articlePosition++;
textView_author.setText(list.get(articlePosition).getAuthor().toString());
textView_date.setText(list.get(articlePosition).getPubDate().toString());
textView_title.setText(list.get(articlePosition).getTitle().toString());
textView_content.loadUrl(list.get(articlePosition).getUri());
}
}
}
}


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/rect_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/ripple_material_light" />
<item android:state_activated="true" android:drawable="@color/ripple_material_light" />
<item android:drawable="@android:color/transparent" />
</selector>
26 changes: 26 additions & 0 deletions app/src/main/res/layout/activity_article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,31 @@
/>
</LinearLayout>
</ScrollView>

<LinearLayout
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="@color/white_93"
android:layout_height="wrap_content">

<ImageButton
android:id="@+id/previous_btn"
android:src="@drawable/ic_keyboard_arrow_up_white_24dp"
android:tint="@color/main_grey_normal"
android:background="@drawable/rect_selector"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="36dp"/>

<ImageButton
android:id="@+id/next_btn"
android:src="@drawable/ic_keyboard_arrow_down_white_24dp"
android:tint="@color/main_grey_normal"
android:background="@drawable/rect_selector"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="36dp"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<color name="theme_primary">#424242</color>
<color name="main_grey_dark">#424242</color>
<color name="main_grey_normal">#9e9e9e</color>
<color name="white_93">#eeffffff</color>
</resources>

0 comments on commit da7327d

Please sign in to comment.