feature_board_view #28

Merged
norangebit merged 19 commits from feature_board_view into develop 2020-01-16 18:33:24 +00:00
8 changed files with 136 additions and 11 deletions
Showing only changes of commit 6c62cc412b - Show all commits

View File

@ -5,7 +5,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

View File

@ -29,7 +29,7 @@ public class DriverActivity extends AppCompatActivity {
sharedPreferences.setBaseUrl("https://board.norangeb.it/");
sharedPreferences.setToken("4waGrVlk0fkLhiQRDgN_rkbIamp4IyB6mThS0IpKbPx");
sharedPreferences.setUserId("");
sharedPreferences.setUserId("jPdkf3a9bmfZWx3GR");
idBoard = findViewById(R.id.idBoard);

View File

@ -9,7 +9,7 @@ import androidx.room.RoomDatabase;
import it.unisannio.ding.ids.wedroid.app.data.dao.WListDao;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
@Database(entities = WList.class, version = 1, exportSchema = false)
@Database(entities = WList.class, version = 2, exportSchema = false)
public abstract class WListDatabase extends RoomDatabase {
private static volatile WListDatabase INSTANCE;
public abstract WListDao wListDao();
@ -22,10 +22,9 @@ public abstract class WListDatabase extends RoomDatabase {
context.getApplicationContext(),
WListDatabase.class,
"wlist_database"
).build();
).fallbackToDestructiveMigration().build();
return INSTANCE;
}
}
}

View File

@ -1,7 +1,9 @@
package it.unisannio.ding.ids.wedroid.app.view;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@ -24,6 +26,8 @@ import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
public class WListsListActivity extends AppCompatActivity {
Toolbar myToolbar;
String boardTitle;
int barColor;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -33,9 +37,9 @@ public class WListsListActivity extends AppCompatActivity {
setSupportActionBar(myToolbar);
Intent i = getIntent();
String boardTitle = i.getStringExtra("barTitle");
boardTitle = i.getStringExtra("barTitle");
Objects.requireNonNull(getSupportActionBar()).setTitle(boardTitle);
int barColor = i.getIntExtra("barColor", 0);
barColor = i.getIntExtra("barColor", 0);
myToolbar.setBackgroundColor(barColor);
PreferenceReader reader =new SharedPreferenceHelper(this);

View File

@ -2,14 +2,19 @@ package it.unisannio.ding.ids.wedroid.app.view.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
@ -20,6 +25,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
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.Card;
import it.unisannio.ding.ids.wedroid.wrapper.entity.Swimlane;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -29,19 +35,25 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
private final LayoutInflater mInflater;
private List<WList> mWLists; // Cached copy of words
private Context mContext;
private ServicesFactory service;
private SharedPreferenceHelper sp;
public WListsAdapter(Context context){
mInflater = LayoutInflater.from(context);
mContext=context;
sp = new SharedPreferenceHelper(mContext);
service = new ServicesFactory(sp);
}
class WListViewHolder extends RecyclerView.ViewHolder{
private final TextView wListItemView;
ListView listView;
Button button;
private WListViewHolder(View itemView){
super(itemView);
wListItemView= itemView.findViewById(R.id.wListTitle);
listView = itemView.findViewById(R.id.listViewCard);
button = itemView.findViewById(R.id.buttonAddCard);
}
}
@ -58,8 +70,6 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
if (mWLists != null) {
final WList current = mWLists.get(position);
final List<String> cardTitle = new ArrayList<>();
SharedPreferenceHelper sp = new SharedPreferenceHelper(mContext);
ServicesFactory service = new ServicesFactory(sp);
service.getCardService().getAllCards(sp.getBoardId(), current.getId()).enqueue(
new Callback<List<Card>>() {
@Override
@ -71,6 +81,13 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
android.R.layout.simple_list_item_1, cardTitle);
holder.listView.setAdapter(adapter);
holder.wListItemView.setText(current.getTitle());
holder.button.setText("Add Card to " + current.getTitle());
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInputDialog(current.getId());
}
});
}
@Override
public void onFailure(Call<List<Card>> call, Throwable t) {
@ -96,4 +113,81 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
mWLists = wList;
notifyDataSetChanged();
}
private void showInputDialog(final String current) {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
View promptView = layoutInflater.inflate(R.layout.alert_new_card, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setView(promptView);
final EditText editText = promptView.findViewById(R.id.edittext);
// setup a dialog window
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if(!editText.getText().toString().matches("")) {
service.getSwimlanesService().getAllSwimlanes(sp.getBoardId()).enqueue(new Callback<List<Swimlane>>() {
@Override
public void onResponse(Call<List<Swimlane>> call, Response<List<Swimlane>> response) {
String idDefaultSwimlane = null;
for(Swimlane swim: response.body()){
if(swim.getTitle().equalsIgnoreCase("default"))
idDefaultSwimlane=swim.getTitle();
}
final Card card = new Card();
card.setTitle(editText.getText().toString());
card.setAuthorId(sp.getUserId());
card.setSwimlaneId(idDefaultSwimlane);
System.out.println("****************" + idDefaultSwimlane);
//card.setDescription("new card from app");
service.getListService().getList(sp.getBoardId(), current).enqueue(new Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>() {
@Override
public void onResponse(Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> response) {
service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() {
@Override
public void onResponse(Call<Card> call, Response<Card> response){
if(response.isSuccessful())
Toast.makeText(mContext, "card posted" ,
Toast.LENGTH_LONG).show();
else
Toast.makeText(mContext, "card unposted" ,
Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<Card> call, Throwable t) {
}
});
}
@Override
public void onFailure(Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, Throwable t) {
}
});
}
@Override
public void onFailure(Call<List<Swimlane>> call, Throwable t) {
}
});
}
else
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}

View File

@ -0,0 +1,20 @@
<?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/enter_card_name"
android:id="@+id/textView" />
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/enter_text_here"
android:padding="10dp" />
</LinearLayout>

View File

@ -14,10 +14,16 @@
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewCard"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent" >
</ListView>
<Button
android:id="@+id/buttonAddCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_card_button" />
</LinearLayout>

View File

@ -9,4 +9,7 @@
<string name="labels">-Labels:</string>
<string name="modified_at">Modified at:</string>
<string name="created_at">Created at:</string>
<string name="add_card_button">Add Card</string>
<string name="enter_text_here">Enter text here...</string>
<string name="enter_card_name">Enter card name</string>
</resources>