Skip to content

Commit e5aa19f

Browse files
author
zhouxingrong
committed
fix add RepoDetail code
1 parent ecf9e0c commit e5aa19f

File tree

10 files changed

+80
-22
lines changed

10 files changed

+80
-22
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.jusenr.androidgithub;
2+
3+
import com.jusenr.androidgithub.utils.Utils;
4+
5+
/**
6+
* Description:
7+
* Copyright : Copyright (c) 2017
8+
* Email : jusenr@163.com
9+
* Author : Jusenr
10+
* Date : 2017/10/13
11+
* Time : 17:05
12+
* Project :androidgithub.
13+
*/
14+
public class MainTest {
15+
16+
public static void main(String[] args) {
17+
String githubTime="2017-10-13T08:11:48Z";
18+
String s = Utils.formatDateGithub(githubTime);
19+
System.out.println(s);
20+
}
21+
}

app/src/main/java/com/jusenr/androidgithub/home/model/interactor/RepoDetailInteractorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.jusenr.androidgithub.user.model.model.UserModel;
1010
import com.jusenr.androidgithub.utils.AccountHelper;
1111
import com.jusenr.androidgithub.utils.Constants;
12-
import com.jusenr.androidgithub.utils.StringUtil;
12+
import com.jusenr.androidgithub.utils.Utils;
1313
import com.jusenr.androidlibrary.di.scope.ActivityScope;
1414

1515
import java.util.ArrayList;
@@ -72,7 +72,7 @@ public RepoDetail call(Repo repo, ArrayList<UserModel> users, ArrayList<Repo> fo
7272
detail.setForks(forks);
7373

7474
// because the readme content is encode with Base64 by github.
75-
readme.content = StringUtil.base64Decode(readme.content);
75+
readme.content = Utils.base64Decode(readme.content);
7676
detail.setReadme(readme);
7777
detail.setContributors(users);
7878
return detail;

app/src/main/java/com/jusenr/androidgithub/home/ui/activity/RepoDetailActivity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
public class RepoDetailActivity extends PTMVPActivity<RepoDetailPresenter> implements RepoDetailContract.View {
3737

38+
@BindView(R.id.ll_root_layout)
39+
LinearLayout mLlRootLayout;
3840
@BindView(R.id.riv_repo_item_view)
3941
RepoItemView mRivRepoItemView;
4042
@BindView(R.id.contributors_count)
@@ -57,12 +59,12 @@ public class RepoDetailActivity extends PTMVPActivity<RepoDetailPresenter> imple
5759
TextView mTvReadmeLabel;
5860
@BindView(R.id.ll_readme_layout)
5961
LinearLayout mLlReadmeLayout;
60-
private String mRepoName;
61-
private String mOwner;
6262

6363
private ForkUserListAdapter mForkUserAdapter;
6464
private ContributorListAdapter mContributorAdapter;
6565

66+
private String mRepoName;
67+
private String mOwner;
6668
private RepoDetail mRepoDetail;
6769

6870
@Override
@@ -102,6 +104,7 @@ protected void onViewCreated(@Nullable Bundle savedInstanceState) {
102104

103105
@Override
104106
public void loadRepoDetailsResult(RepoDetail detail) {
107+
mLlRootLayout.setVisibility(View.VISIBLE);
105108
mRepoDetail = detail;
106109
mOwner = detail.getBaseRepo().getOwner().getLogin();
107110
mRepoName = detail.getBaseRepo().getName();
@@ -133,11 +136,15 @@ public void loadRepoDetailsFailed(int code, String msg) {
133136
@Override
134137
public void starRepoResult(boolean b) {
135138
Snackbar.make(mRivRepoItemView, b ? "Star Success" : "Star Failed", Snackbar.LENGTH_LONG).show();
139+
if (b)
140+
mPresenter.onLoadRepoDetails(mOwner, mRepoName);
136141
}
137142

138143
@Override
139144
public void unstarRepoResult(boolean b) {
140145
Snackbar.make(mRivRepoItemView, b ? "UnStar Success" : "UnStar Failed", Snackbar.LENGTH_LONG).show();
146+
if (b)
147+
mPresenter.onLoadRepoDetails(mOwner, mRepoName);
141148
}
142149

143150
@Override
@@ -162,6 +169,7 @@ public void onViewClicked(View view) {
162169
}
163170

164171
private void initViews() {
172+
mLlRootLayout.setVisibility(View.INVISIBLE);
165173
mContributorAdapter = new ContributorListAdapter(null);
166174
mContributorAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
167175
@Override

app/src/main/java/com/jusenr/androidgithub/home/ui/adapter/RepoListRecyclerAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.chad.library.adapter.base.BaseViewHolder;
55
import com.jusenr.androidgithub.R;
66
import com.jusenr.androidgithub.home.model.model.Repo;
7-
import com.jusenr.androidgithub.utils.StringUtil;
7+
import com.jusenr.androidgithub.utils.Utils;
88

99
import java.util.List;
1010

@@ -19,7 +19,7 @@ public RepoListRecyclerAdapter(List<Repo> data) {
1919

2020
@Override
2121
protected void convert(BaseViewHolder holder, Repo repo) {
22-
holder.setText(R.id.name, StringUtil.replaceAllBlank(repo.getName()));
23-
holder.setText(R.id.desc, StringUtil.trimNewLine(repo.getDescription()));
22+
holder.setText(R.id.name, Utils.replaceAllBlank(repo.getName()));
23+
holder.setText(R.id.desc, Utils.trimNewLine(repo.getDescription()));
2424
}
2525
}

app/src/main/java/com/jusenr/androidgithub/user/ui/activity/UserActivity.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.text.TextUtils;
77
import android.view.MenuItem;
88
import android.view.View;
9+
import android.widget.LinearLayout;
910

1011
import com.jusenr.androidgithub.R;
1112
import com.jusenr.androidgithub.base.PTMVPActivity;
@@ -25,6 +26,8 @@
2526

2627
public class UserActivity extends PTMVPActivity<UserPresenter> implements UserContract.View {
2728

29+
@BindView(R.id.ll_root_layout)
30+
LinearLayout mLlRootLayout;
2831
@BindView(R.id.user_card)
2932
UserCardView mUserCardView;
3033

@@ -61,11 +64,15 @@ protected void onViewCreated(@Nullable Bundle savedInstanceState) {
6164
setTitle(mUsername);
6265
mPresenter.onUserInfo(mUsername);
6366
}
67+
68+
mLlRootLayout.setVisibility(View.INVISIBLE);
6469
}
6570

6671
@Override
6772
public void getUserinfoResult(UserModel bean) {
68-
mUserCardView.setUser(bean);
73+
mLlRootLayout.setVisibility(View.VISIBLE);
74+
if (bean != null)
75+
mUserCardView.setUser(bean);
6976
}
7077

7178
@Override

app/src/main/java/com/jusenr/androidgithub/utils/StringUtil.java renamed to app/src/main/java/com/jusenr/androidgithub/utils/Utils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import android.text.TextUtils;
44
import android.util.Base64;
55

6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
69
import java.util.regex.Matcher;
710
import java.util.regex.Pattern;
811

912
/**
1013
* Created by mingjun on 16/7/20.
1114
*/
12-
public class StringUtil {
15+
public class Utils {
1316

1417
public static String replaceAllBlank(String str) {
1518
if (TextUtils.isEmpty(str)) return "";
@@ -35,4 +38,22 @@ public static String base64Decode(String originalString) {
3538

3639
return new String(Base64.decode(originalString, 0));
3740
}
41+
42+
/**
43+
* Github时间字符串格式化
44+
*
45+
* @param githubTime 2017-10-13T08:11:48Z
46+
* @return 时间字符串
47+
*/
48+
public static String formatDateGithub(String githubTime) {
49+
githubTime = githubTime.replace("Z", " UTC");
50+
try {
51+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z");
52+
Date date = formatter.parse(githubTime);
53+
return date.toLocaleString();
54+
} catch (ParseException e) {
55+
e.printStackTrace();
56+
}
57+
return null;
58+
}
3859
}

app/src/main/java/com/jusenr/androidgithub/widgets/RepoItemView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.flyco.labelview.LabelView;
1414
import com.jusenr.androidgithub.R;
1515
import com.jusenr.androidgithub.home.model.model.Repo;
16+
import com.jusenr.androidgithub.utils.Utils;
1617
import com.jusenr.androidlibrary.widgets.fresco.FrescoImageView;
1718

1819
import butterknife.BindView;
@@ -80,9 +81,8 @@ public void setRepo(Repo repo) {
8081
} else {
8182
mLabelView.setVisibility(GONE);
8283
}
83-
84-
mUpdateTime.setText(repo.getUpdated_at());
85-
mStarCount.setText(String.valueOf(repo.getStargazers_count()));
84+
mUpdateTime.setText(Utils.formatDateGithub(repo.getUpdated_at()));
85+
mStarCount.setText(Integer.toString(repo.getStargazers_count()));
8686

8787
mStarIcon.setImageResource(repo.isStarred() ? R.mipmap.ic_star_selected : R.mipmap.ic_star);
8888
}

app/src/main/res/layout/activity_repo_detail.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@
5555
<com.jusenr.androidlibrary.widgets.recyclerView.BaseRecyclerView
5656
android:id="@+id/rlv_contributor_list"
5757
android:layout_width="match_parent"
58-
android:layout_height="60dp"
59-
android:layout_marginTop="2dp"
60-
app:columnCount="1"
61-
app:layoutMode="grid"/>
58+
android:layout_height="50dp"
59+
android:layout_marginTop="3dp"
60+
app:layoutMode="horizontal"/>
6261

6362
</LinearLayout>
6463

@@ -91,10 +90,9 @@
9190
<com.jusenr.androidlibrary.widgets.recyclerView.BaseRecyclerView
9291
android:id="@+id/rlv_fork_list"
9392
android:layout_width="match_parent"
94-
android:layout_height="60dp"
95-
android:layout_marginTop="2dp"
96-
app:columnCount="1"
97-
app:layoutMode="grid"/>
93+
android:layout_height="50dp"
94+
android:layout_marginTop="3dp"
95+
app:layoutMode="horizontal"/>
9896

9997
</LinearLayout>
10098

app/src/main/res/layout/activity_user.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
android:padding="10dp">
77

88
<LinearLayout
9+
android:id="@+id/ll_root_layout"
910
android:layout_width="match_parent"
1011
android:layout_height="match_parent"
1112
android:orientation="vertical">

app/src/main/res/layout/layout_item_user.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
<com.jusenr.androidlibrary.widgets.fresco.FrescoImageView
88
android:id="@+id/user_icon"
99
style="@style/image_round_4dp"
10-
android:layout_width="60dp"
11-
android:layout_height="60dp"
10+
android:layout_width="50dp"
11+
android:layout_height="50dp"
12+
android:padding="2dp"
13+
android:layout_gravity="center"
1214
android:scaleType="centerInside"/>
1315

1416
</LinearLayout>

0 commit comments

Comments
 (0)