Add view Board and WLists v1
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Umberto Furno 2019-12-29 19:06:12 +01:00
parent fda86e1f10
commit baced120f9
12 changed files with 419 additions and 9 deletions

View File

@ -1,21 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="it.unisannio.ding.ids.wedroid.app"> package="it.unisannio.ding.ids.wedroid.app">
<uses-permission android:name="android.permission.INTERNET" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
<activity android:name=".MainActivity"> tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".DriverActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".view.BoardViewActivity" />
<activity android:name=".view.WListsListActivity"
android:label="WList"
android:theme="@style/AppTheme.NoActionBar"/>
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,46 @@
package it.unisannio.ding.ids.wedroid.app;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.app.view.BoardViewActivity;
public class DriverActivity extends AppCompatActivity {
SharedPreferenceHelper sharedPreferences;
EditText idBoard;
Button send;
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = new SharedPreferenceHelper(this);
String baseUrl = sharedPreferences.getBaseUrl();
String token = sharedPreferences.getToken();
String userId = sharedPreferences.getUserId();
sharedPreferences.setBaseUrl("https://board.norangeb.it/");
sharedPreferences.setToken("4waGrVlk0fkLhiQRDgN_rkbIamp4IyB6mThS0IpKbPx");
sharedPreferences.setUserId("");
idBoard = findViewById(R.id.idBoard);
send= findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), BoardViewActivity.class);
i.putExtra("idBoard", idBoard.getText().toString());
startActivity(i);
}
});
}
}

View File

@ -0,0 +1,66 @@
package it.unisannio.ding.ids.wedroid.app.view;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.wrapper.entity.Board;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class BoardViewActivity extends AppCompatActivity {
TextView boardTitle;
Button getLists;
SharedPreferenceHelper sp;
ServicesFactory service;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_board_view);
Intent i = getIntent();
final String idBoard= i.getStringExtra("idBoard");
boardTitle = findViewById(R.id.title_board);
getLists = findViewById(R.id.getLists);
sp = new SharedPreferenceHelper(this);
sp.setBoardId(idBoard);
initializeUI(idBoard);
getLists.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), WListsListActivity.class);
i.putExtra("idBoard", idBoard);
startActivity(i);
}
});
}
private void initializeUI(String idBoard) {
service = new ServicesFactory(sp);
service.getBoardService().getBoard(idBoard).enqueue(new Callback<Board>() {
@Override
public void onResponse(Call<Board> call, Response<Board> response) {
boardTitle.setText(boardTitle.getText().toString() + response.body().getTitle());
}
@Override
public void onFailure(Call<Board> call, Throwable t) {
boardTitle.setText(t.toString());
}
});
}
}

View File

@ -0,0 +1,48 @@
package it.unisannio.ding.ids.wedroid.app.view;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.app.view.adapter.WListsAdapter;
import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
public class WListsListActivity extends AppCompatActivity {
private WListsListViewModel viewModel;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wlists_view);
PreferenceReader reader =new SharedPreferenceHelper(this);
RecyclerView recyclerView = findViewById(R.id.recyclerviewWList);
final WListsAdapter adapter = new WListsAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
//linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//recyclerView.setHasFixedSize(true);
viewModel = new ViewModelProvider(this).get(WListsListViewModel.class);
viewModel.getAllWLists().observe(this, new Observer<List<WList>>() {
@Override
public void onChanged(List<WList> wLists) {
adapter.setWLists(wLists);
}
});
}
}

View File

@ -0,0 +1,99 @@
package it.unisannio.ding.ids.wedroid.app.view.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewHolder> {
private final LayoutInflater mInflater;
private List<WList> mWLists; // Cached copy of words
public WListsAdapter(Context context) { mInflater = LayoutInflater.from(context); }
class WListViewHolder extends RecyclerView.ViewHolder{
private final TextView wListItemView;
private WListViewHolder(View itemView){
super(itemView);
wListItemView= itemView.findViewById(R.id.wListTitle);
}
}
@NonNull
@Override
public WListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = mInflater.inflate(R.layout.wlist_recyclerview_item, parent, false);
return new WListViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull WListViewHolder holder, int position) {
if (mWLists != null) {
WList current = mWLists.get(position);
holder.wListItemView.setText(current.getTitle());
} else {
// Covers the case of data not being ready yet.
holder.wListItemView.setText("No wList");
}
}
@Override
public int getItemCount() {
if (mWLists != null)
return mWLists.size();
else return 0;
}
public void setWLists(List<WList> wList){
mWLists = wList;
notifyDataSetChanged();
}
}
/** Vecchia versione
private List<WList> wLists;
private Context context;
public WListsAdapter(Context context, List<WList> wLists){
this.wLists = wLists;
this.context = context;
}
public class WListViewHolder extends RecyclerView.ViewHolder {
private TextView title;
public WListViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.zWListTitle);
}
}
@NonNull
@Override
public WListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.z_wlist_recycle_item, parent, false);
return new WListViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull WListViewHolder holder, int position) {
WList wList = wLists.get(position);
holder.title.setText(wList.getTitle());
}
@Override
public int getItemCount() {
return 0;
}
**/

View File

@ -0,0 +1,40 @@
package it.unisannio.ding.ids.wedroid.app.viewModel;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import java.util.List;
import it.unisannio.ding.ids.wedroid.app.data.database.WListDatabase;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
import it.unisannio.ding.ids.wedroid.app.data.repository.WListRepository;
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader;
import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
public class WListsListViewModel extends AndroidViewModel {
private WListRepository wListRepository;
private LiveData<List<WList>> allWLists;
public WListsListViewModel(@NonNull Application application) {
super(application);
PreferenceReader reader = new SharedPreferenceHelper(application);
wListRepository = new WListRepository(
WListDatabase.getDatabase(application).wListDao(),
ServicesFactory.Companion.getInstance(reader).getListService(),
reader);
allWLists = wListRepository.getAllWLists();
}
public LiveData<List<WList>> getAllWLists(){
return allWLists;
}
public void refresh() {
wListRepository.synchronize();
}
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="27dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title_board"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Board title: " />
<Space
android:layout_width="match_parent"
android:layout_height="27dp" />
<Button
android:id="@+id/getLists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get lists" />
</LinearLayout>
</LinearLayout>

View File

@ -6,13 +6,35 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.033"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="16dp">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Hello World!" android:layout_marginLeft="1dp"
app:layout_constraintBottom_toBottomOf="parent" android:text="Activity driver that passed id board" />
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" <EditText
app:layout_constraintTop_toTopOf="parent" /> android:id="@+id/idBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="ID_BOARD" />
<Button
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerviewWList"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/wlist_recyclerview_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,12 @@
<?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="wrap_content">
<TextView
android:id="@+id/wListTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright" />
</LinearLayout>

View File

@ -0,0 +1,3 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -8,4 +8,14 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources> </resources>