-
Couldn't load subscription status.
- Fork 11
17023149 邹伟强 95 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
17023149 邹伟强 95 #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,68 @@ | ||
| package com.nd.frt.recentconversation; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.LinearLayoutManager; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.Menu; | ||
| import android.view.MenuItem; | ||
|
|
||
| import com.nd.frt.recentconversation.adapter.UserAdapter; | ||
| import com.nd.frt.recentconversation.activity.DetailActivity; | ||
| import com.nd.frt.recentconversation.adapter.Useradapter; | ||
| import com.nd.frt.recentconversation.model.UserInfo; | ||
| import com.nd.frt.recentconversation.service.UserInfoService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class MainActivity extends AppCompatActivity { | ||
|
|
||
| private Useradapter mUserAdapter; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
| UserInfoService userInfoService = new UserInfoService(); | ||
| List<UserInfo> userInfos = userInfoService.getUserInfos(this); | ||
| UserAdapter userAdapter = new UserAdapter(userInfos); | ||
| RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rvRecyclerView); | ||
| recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); | ||
| recyclerView.setAdapter(userAdapter); | ||
| RecyclerView rvUsers = findViewById(R.id.rvUsers); | ||
| rvUsers.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL,false)); | ||
| mUserAdapter = new Useradapter(userInfos); | ||
| rvUsers.setAdapter(mUserAdapter); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| getMenuInflater().inflate(R.menu.menu_main,menu); | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| if (item.getItemId() == R.id.menu_add){ | ||
| UserInfo userInfo = new UserInfo(); | ||
| userInfo.userName = "zouweiqiang"; | ||
| userInfo.content = "1070911992@qq.com"; | ||
| userInfo.avatarUrl = "https://randomuser.me/api/portraits/women/94.jpg"; | ||
| mUserAdapter.add(userInfo); | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
| super.onActivityResult(requestCode, resultCode, data); | ||
| if (requestCode == RESULT_OK){ | ||
| if (data != null) { | ||
| UserInfo userInfo = (UserInfo) data.getSerializableExtra((DetailActivity.PARAM_USER_INFO)); | ||
| int index = data.getIntExtra(DetailActivity.PARAM_USER_INDEX,0); | ||
| mUserAdapter.edit(index,userInfo); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.nd.frt.recentconversation.activity; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.support.v7.app.ActionBar; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.view.MenuItem; | ||
| import android.view.View; | ||
| import android.widget.EditText; | ||
| import android.widget.ImageView; | ||
|
|
||
| import com.bumptech.glide.Glide; | ||
| import com.nd.frt.recentconversation.R; | ||
| import com.nd.frt.recentconversation.model.UserInfo; | ||
|
|
||
| public class DetailActivity extends AppCompatActivity { | ||
|
|
||
| public static final String PARAM_USER_INFO = "user_info"; | ||
| public static final String PARAM_USER_INDEX = "user_index"; | ||
| private UserInfo mUserInfo; | ||
| private int mUserIndex; | ||
|
|
||
| public static void start(Activity context, int index, UserInfo userInfo, int requestCode) { | ||
| Intent starter = new Intent(context, DetailActivity.class); | ||
| starter.putExtra(PARAM_USER_INFO,userInfo); | ||
| starter.putExtra(PARAM_USER_INDEX,index); | ||
| context.startActivityForResult(starter,requestCode); | ||
| } | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_detail); | ||
| ActionBar supportActionBar = getSupportActionBar(); | ||
| assert supportActionBar != null; | ||
| supportActionBar.setDisplayHomeAsUpEnabled(true); | ||
| Intent intent = getIntent(); | ||
| mUserInfo = ((UserInfo) intent.getSerializableExtra(PARAM_USER_INFO)); | ||
| mUserIndex = intent.getIntExtra(PARAM_USER_INDEX,0); | ||
| supportActionBar.setTitle(mUserInfo.userName); | ||
| supportActionBar.setSubtitle(mUserInfo.content); | ||
| final EditText etUserName = findViewById(R.id.etUserName); | ||
| ImageView ivAvatar = findViewById(R.id.ivAvatar); | ||
| Glide.with(this) | ||
| .load(mUserInfo.avatarUrl) | ||
| .into(ivAvatar); | ||
| findViewById(R.id.btnOk).setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View view) { | ||
| mUserInfo.userName = etUserName.getText().toString(); | ||
| Intent intentResult = new Intent(); | ||
| intentResult.putExtra(PARAM_USER_INFO,mUserInfo); | ||
| intentResult.putExtra(PARAM_USER_INDEX,mUserIndex); | ||
| setResult(RESULT_OK,intentResult); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| if (item.getItemId() == android.R.id.home){ | ||
| finish(); | ||
| return true; | ||
| } | ||
| return super.onOptionsItemSelected(item); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package com.nd.frt.recentconversation.adapter; | ||
|
|
||
| import android.app.Activity; | ||
| import android.support.annotation.NonNull; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.bumptech.glide.Glide; | ||
| import com.nd.frt.recentconversation.R; | ||
| import com.nd.frt.recentconversation.activity.DetailActivity; | ||
| import com.nd.frt.recentconversation.model.UserInfo; | ||
| import com.nd.frt.recentconversation.viewholder.UserViewHoldere; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Useradapter extends RecyclerView.Adapter<UserViewHoldere> { | ||
|
|
||
|
|
||
| private static final int REQUEST_EDIT_USER_INFO = 0x1001; | ||
| private List<UserInfo> mUserinfos; | ||
|
|
||
| public Useradapter(List<UserInfo>userInfos) { | ||
| mUserinfos = userInfos; | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public UserViewHoldere onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | ||
| LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext()); | ||
| View itemView = layoutInflater.inflate(R.layout.item_user, viewGroup, false); | ||
| return new UserViewHoldere(itemView); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(@NonNull UserViewHoldere userViewHoldere, final int position) { | ||
| final UserInfo userInfo = mUserinfos.get(position); | ||
| Glide.with(userViewHoldere.itemView.getContext()) | ||
| .load(userInfo.avatarUrl) | ||
| .into(userViewHoldere.mIvAvatar); | ||
| userViewHoldere.mTvUserName.setText(userInfo.userName); | ||
| userViewHoldere.mTvEmail.setText(userInfo.content); | ||
| userViewHoldere.itemView.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View view) { | ||
| DetailActivity.start((Activity) view.getContext(),position,userInfo,REQUEST_EDIT_USER_INFO); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 无用空行 |
||
| } | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return mUserinfos.size(); | ||
| } | ||
| public void add(UserInfo userInfo){ | ||
| mUserinfos.add(userInfo); | ||
| notifyDataSetChanged(); | ||
| } | ||
| public void edit(int index, UserInfo userInfo){ | ||
| mUserinfos.set(index,userInfo); | ||
| notifyDataSetChanged(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportWidth="24" | ||
| android:viewportHeight="24" | ||
| android:tint="#FFFFFF"> | ||
| <path | ||
| android:fillColor="#FF000000" | ||
| android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/> | ||
| </vector> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?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" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:layout_gravity="center_horizontal" | ||
| android:padding="10dp" | ||
| android:orientation="vertical" | ||
| tools:context=".activity.DetailActivity"> | ||
| <ImageView | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 增加空行 |
||
| android:contentDescription="@string/avatar" | ||
| android:id="@+id/ivAvatar" | ||
| android:layout_width="96dp" | ||
| android:layout_height="96dp" /> | ||
| <EditText | ||
| android:id="@+id/etUserName" | ||
| android:layout_width="match_parent" | ||
| android:layout_marginTop="10dp" | ||
| android:layout_height="wrap_content" | ||
| android:hint="@string/username" | ||
| android:inputType="text" | ||
| tools:ignore="Autofill"/> | ||
| <Button | ||
| android:id="@+id/btnOk" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="@android:string/ok"/> | ||
|
|
||
|
|
||
| </LinearLayout> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,15 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <android.support.v7.widget.RecyclerView | ||
| android:id="@+id/rvRecyclerView" | ||
| android:id="@+id/rvUsers" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical" /> | ||
| android:layout_height="match_parent"/> | ||
|
|
||
|
|
||
| </FrameLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无用空行