Skip to content

Commit

Permalink
增加分享功能
Browse files Browse the repository at this point in the history
  • Loading branch information
laucherish committed Mar 25, 2016
1 parent 4e2454e commit 74aab12
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import io.github.laucherish.purezhihud.R;
import io.github.laucherish.purezhihud.base.BaseActivity;
Expand Down Expand Up @@ -46,13 +45,4 @@ private void showNewsDetailFragment(News news) {
transaction.commit();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.github.laucherish.purezhihud.ui.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
Expand All @@ -21,6 +25,7 @@
import io.github.laucherish.purezhihud.bean.News;
import io.github.laucherish.purezhihud.bean.NewsDetail;
import io.github.laucherish.purezhihud.network.manager.RetrofitManager;
import io.github.laucherish.purezhihud.ui.activity.AboutActivity;
import io.github.laucherish.purezhihud.ui.activity.NewsDetailActivity;
import io.github.laucherish.purezhihud.utils.HtmlUtil;
import io.github.laucherish.purezhihud.utils.L;
Expand Down Expand Up @@ -65,6 +70,7 @@ protected int getLayoutId() {
@Override
protected void afterCreate(Bundle savedInstanceState) {
mNews = getArguments().getParcelable(NewsDetailActivity.KEY_NEWS);
setHasOptionsMenu(true);
init();
loadData();
}
Expand All @@ -77,6 +83,29 @@ public static Fragment newInstance(News news) {
return fragment;
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_detail,menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
getActivity().onBackPressed();
return true;
case R.id.menu_action_share:
share();
return true;
case R.id.menu_action_about:
AboutActivity.start(getActivity());
return true;
default:
return super.onOptionsItemSelected(item);
}
}

private void init() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(mToolbar);
Expand Down Expand Up @@ -135,4 +164,12 @@ public void hideProgress() {
mPbLoading.setVisibility(View.GONE);
}

private void share() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share));
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_from) + mNews.getTitle() + ",http://daily.zhihu.com/story/" + mNews.getId());
startActivity(Intent.createChooser(intent, mNews.getTitle()));
}

}
Binary file added app/src/main/res/drawable-hdpi/ic_share.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/drawable-mdpi/ic_share.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/drawable-xhdpi/ic_share.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/drawable-xxhdpi/ic_share.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/drawable-xxxhdpi/ic_share.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/drawable/ic_share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions app/src/main/res/menu/menu_detail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_action_share"
android:title=""
android:icon="@drawable/ic_share"
app:showAsAction="always"
/>

<item
android:id="@+id/menu_action_about"
android:title="@string/about"
/>

</menu>
4 changes: 3 additions & 1 deletion app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_action_about"
android:title="@string/about"
app:showAsAction="never"
/>

</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<string name="test_title">新闻标题新闻标题新闻标题新闻标题新闻标题新闻标题,不忘初心,方得始终</string>
<string name="test_source">图片来源</string>
<string name="share">分享</string>
<string name="share_from">来自「纯净日报」的分享:</string>

<string name="about_introduce">「纯净日报」- 给您最纯粹的阅读体验。\n\n开源是必须的,软件采用RxJava + Retrofit + OkHttp框架实现,喜欢的朋友请Star,欢迎一起学习讨论。\n\n你的支持将是我最大的动力与褒奖!</string>
<string name="about_menu_action_share">分享</string>
Expand Down

0 comments on commit 74aab12

Please sign in to comment.