Skip to content
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

#8 #251 完整版App #1803

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions students/soft1714080902206/ContentActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.exampler.mynews;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.exampler.mynews.databinding.ContentActivityBinding;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ContentActivity extends AppCompatActivity {

private ContentActivityBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

binding = DataBindingUtil.setContentView(this, R.layout.content_activity);

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
Date date = new Date(System.currentTimeMillis());
Intent intent = getIntent();
String title = intent.getStringExtra("title");
String image = intent.getStringExtra("image");
String time = simpleDateFormat.format(date);
String content = intent.getStringExtra("content");

News news = new News(title, image, time, content);

NewsVM newsVM = new NewsVM(news);

binding.setVm(newsVM);

}
}
998 changes: 846 additions & 152 deletions students/soft1714080902206/MainActivity.java

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions students/soft1714080902206/News.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.exampler.mynews;

public class News {

private String title;

private String imageId;

private String time;

private String content;

public News(String title, String imageId, String time, String content) {
this.title = title;
this.imageId = imageId;
this.time = time;
this.content = content;
}

public String getTitle() {
return title;
}

public String getContent() {
return content;
}

public String getImageId() {
return imageId;
}

public String getTime() {
return time;
}

public void setTitle(String title) {
this.title = title;
}

public void setImageId(String imageId) {
this.imageId = imageId;
}

public void setTime(String time) {
this.time = time;
}

public void setContent(String content) {
this.content = content;
}
}
103 changes: 103 additions & 0 deletions students/soft1714080902206/NewsAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.exampler.mynews;

import android.content.Intent;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder>{

private List<News> mNewsList;

public interface OnItemOnClickListener{
void onItemLongOnClick(View view, int pos);
}

private OnItemOnClickListener mOnItemOnClickListener;

public void setOnItemClickListener(OnItemOnClickListener listener) {
this.mOnItemOnClickListener = listener;
}


static class ViewHolder extends RecyclerView.ViewHolder {
ViewDataBinding binding;
View newsView;

public ViewHolder(ViewDataBinding binding) {
super(binding.getRoot());
newsView = binding.getRoot();
this.binding=binding;
}
}

public NewsAdapter(List<News> newsList) {
mNewsList = newsList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, final int Type) {
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
ViewDataBinding binding= DataBindingUtil.inflate(inflater,R.layout.activity_news,parent,false);
final ViewHolder holder = new ViewHolder(binding);
holder.newsView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
int position = holder.getAdapterPosition();
News news = mNewsList.get(position);
Intent intent = new Intent(v.getContext(), ContentActivity.class);
intent.putExtra("title", news.getTitle());
intent.putExtra("image", news.getImageId());
intent.putExtra("time", news.getTime());
intent.putExtra("content", news.getContent());
v.getContext().startActivity(intent);
}
});
return holder;
}


@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
ViewDataBinding binding=holder.binding;
NewsVM viewModel=new NewsVM(mNewsList.get(position));
binding.setVariable(BR.vm,viewModel);
binding.setVariable(BR.adapter,this);
//立即重新绑定数据
binding.executePendingBindings();
holder.newsView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
mOnItemOnClickListener.onItemLongOnClick(holder.newsView, position);
return false;
}
});
}


@Override
public int getItemCount() {
return mNewsList.size();
}

@BindingAdapter("app:uri")
public static void setImage(ImageView imageView , String uri){
if (uri!=null){
Glide.with(imageView.getContext())
.load(uri)
.into(imageView);
}
}

}
55 changes: 55 additions & 0 deletions students/soft1714080902206/NewsVM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.exampler.mynews;

import android.databinding.BaseObservable;
import android.databinding.Bindable;

public class NewsVM extends BaseObservable {

private News news;

public NewsVM(News news) {
this.news = news;
}

@Bindable
public String getTitle() {
return news.getTitle();
}

@Bindable
public String getImageId() {
return news.getImageId();
}

@Bindable
public String getContent() {
return news.getContent();
}

@Bindable
public String getTime() {
return news.getTime();
}

public void setTitle(String title) {
news.setTitle(title);
notifyPropertyChanged(BR.title);
}

public void setImageId(String imageId) {
news.setImageId(imageId);
notifyPropertyChanged(BR.imageId);
}

public void setTime(String time) {
news.setTime(time);
notifyPropertyChanged(BR.time);
}

public void setContent(String content) {
news.setContent(content);
notifyPropertyChanged(BR.content);
}

}

38 changes: 18 additions & 20 deletions students/soft1714080902206/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<Button
android:id="@+id/take_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Take Photo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/chosse_from_album"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Choose From Album" />

<ImageView
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

</layout>
50 changes: 50 additions & 0 deletions students/soft1714080902206/activity_news.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>
<variable
name="vm"
type="com.exampler.mynews.NewsVM"/>
<variable
name="adapter"
type="com.exampler.mynews.NewsAdapter"/>

</data>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/image_view"
app:uri="@{vm.imageId}"
android:scaleType="fitCenter"
android:layout_width="100dp"
android:layout_height="100dp" />

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:id="@+id/title_text_view"
android:text="@{vm.title}"
android:layout_width="match_parent"
android:layout_height="90dp"
android:textSize="22dp"/>

<TextView
android:id="@+id/time_text_view"
android:text="@{vm.time}"
android:layout_width="match_parent"
android:layout_height="10dp"
android:gravity="right"
android:textSize="8dp"
android:textColor="#555"/>
</LinearLayout>

</LinearLayout>

</layout>
Loading