diff --git a/app/src/main/java/com/wargamobile/android/NotifActivity.java b/app/src/main/java/com/wargamobile/android/NotifActivity.java index 4c207ffa90bf5260b67ad2bcdc5d6910472530a7..20f65cc96fea0c10307a7f59b2af0eee969f3be6 100644 --- a/app/src/main/java/com/wargamobile/android/NotifActivity.java +++ b/app/src/main/java/com/wargamobile/android/NotifActivity.java @@ -2,12 +2,29 @@ package com.wargamobile.android; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import java.util.ArrayList; public class NotifActivity extends AppCompatActivity { + ArrayList<Notification> notifications; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notification_page); + + RecyclerView rvNotif = (RecyclerView) findViewById(R.id.rv_notifications); + + // Initialize contacts + notifications = Notification.createNotificationsList(20); + // Create adapter passing in the sample user data + NotifAdapter adapter = new NotifAdapter(notifications); + // Attach the adapter to the recyclerview to populate items + rvNotif.setAdapter(adapter); + // Set layout manager to position the items + rvNotif.setLayoutManager(new LinearLayoutManager(this)); + // That's all! } } diff --git a/app/src/main/java/com/wargamobile/android/NotifAdapter.java b/app/src/main/java/com/wargamobile/android/NotifAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..497fce7a4599f677b2ea031a0cb93fac937551db --- /dev/null +++ b/app/src/main/java/com/wargamobile/android/NotifAdapter.java @@ -0,0 +1,88 @@ +package com.wargamobile.android; + +import android.content.Context; +import android.media.Image; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; +import com.wargamobile.android.Notification; +import com.wargamobile.android.R; +import java.util.List; + +public class NotifAdapter extends + RecyclerView.Adapter<NotifAdapter.ViewHolder> { + + private final int TYPE_SURVEY = 0; + private final int TYPE_POLLING = 1; + + public class ViewHolder extends RecyclerView.ViewHolder { + public TextView nameTextView; + public TextView detailTextView; + public ImageView iconImage; + public Button isiButton; + + public ViewHolder(View itemView) { + super(itemView); + nameTextView = (TextView) itemView.findViewById(R.id.notification_name); + detailTextView = (TextView) itemView.findViewById(R.id.notification_detail); + iconImage = (ImageView) itemView.findViewById(R.id.notif_icon_image); + isiButton = (Button) itemView.findViewById(R.id.btn_isi_survey_polling); + } + + } + // Store a member variable for the contacts + private List<Notification> mNotifications; + + // Pass in the contact array into the constructor + public NotifAdapter(List<Notification> notifications) { + mNotifications = notifications; + } + + // Usually involves inflating a layout from XML and returning the holder + @Override + public NotifAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate the custom layout + View contactView = inflater.inflate(R.layout.notification_items, parent, false); + + // Return a new holder instance + ViewHolder viewHolder = new ViewHolder(contactView); + return viewHolder; + } + + // Involves populating data into the item through holder + @Override + public void onBindViewHolder(NotifAdapter.ViewHolder viewHolder, int position) { + // Get the data model based on position + Notification notif = mNotifications.get(position); + + // Set item views based on your views and data model + TextView nameTextView = viewHolder.nameTextView; + TextView detailTextView = viewHolder.detailTextView; + ImageView iconImage = viewHolder.iconImage; + Button isiButton = viewHolder.isiButton; + + nameTextView.setText(notif.getmName()); + detailTextView.setText(notif.getmDetail()); + if (notif.getmType() == TYPE_SURVEY){ // TYPE_SURVEY = 0 + iconImage.setImageResource(R.drawable.notif_survey); + } + else if (notif.getmType() == TYPE_POLLING){ // TYPE_POLLING = 1 + iconImage.setImageResource(R.drawable.notif_polling); + } + isiButton.setText(notif.isFilled() ? "Terisi" : "Isi"); + isiButton.setEnabled(!notif.isFilled()); + } + + // Returns the total count of items in the list + @Override + public int getItemCount() { + return mNotifications.size(); + } +} diff --git a/app/src/main/java/com/wargamobile/android/Notification.java b/app/src/main/java/com/wargamobile/android/Notification.java new file mode 100644 index 0000000000000000000000000000000000000000..3c68a390601412211b11c4e01f89e94327748daf --- /dev/null +++ b/app/src/main/java/com/wargamobile/android/Notification.java @@ -0,0 +1,68 @@ +package com.wargamobile.android; + +import java.util.ArrayList; + +public class Notification { + private String mName; + private String mDetail; + private int mType; + private boolean isFilled; // Whether the survey/polling is filled or not + + public String getmName() { + return mName; + } + + public void setmName(String mName) { + this.mName = mName; + } + + public String getmDetail() { + return mDetail; + } + + public void setmDetail(String mDetail) { + this.mDetail = mDetail; + } + + public boolean isFilled() { + return isFilled; + } + + public void setFilled(boolean filled) { + isFilled = filled; + } + + public int getmType() { + return mType; + } + + public void setmType(int mType) { + this.mType = mType; + } + + public static ArrayList<Notification> createNotificationsList(int numNotifications) { + ArrayList<Notification> Notifications = new ArrayList<Notification>(); + + for (int i = 1; i <= numNotifications; i++) { + Notification notif = new Notification(); + if (i % 2 == 0){ + notif.setmName("[Polling] - Judul Polling "+i); + notif.setmDetail("Some details of the polling"); + notif.setmType(1); + } + else{ + notif.setmName("[Survey] - Judul Survey "+i); + notif.setmDetail("Some details of the survey"); + notif.setmType(0); + } + if (i % 3 == 0){ + notif.setFilled(true); + } + else{ + notif.setFilled(false); + } + Notifications.add(notif); + } + return Notifications; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/notif_polling.png b/app/src/main/res/drawable/notif_polling.png new file mode 100644 index 0000000000000000000000000000000000000000..08965a11a2a411816aca8805752f2a5825e68aab Binary files /dev/null and b/app/src/main/res/drawable/notif_polling.png differ diff --git a/app/src/main/res/drawable/notif_survey.png b/app/src/main/res/drawable/notif_survey.png new file mode 100644 index 0000000000000000000000000000000000000000..b1ec1938fed2e896f2e82c26bd7c4c8f5cfa2238 Binary files /dev/null and b/app/src/main/res/drawable/notif_survey.png differ diff --git a/app/src/main/res/layout/notification_items.xml b/app/src/main/res/layout/notification_items.xml index f03d23479dee4026ba5306387eac2f0967075c10..0f865c5c3f5494118b60de5d63595fafd5b699d1 100644 --- a/app/src/main/res/layout/notification_items.xml +++ b/app/src/main/res/layout/notification_items.xml @@ -1,36 +1,96 @@ <?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:id="@+id/linearLayout" + android:layout_width="match_parent" + android:layout_height="75dp" + android:paddingTop="10dp" + android:paddingBottom="10dp" + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:orientation="horizontal"> + + + <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:id="@+id/notif_layout" android:layout_width="match_parent" - android:layout_height="75dp"> - + android:layout_height="match_parent" + > <ImageView - android:id="@+id/imageView" - android:layout_width="50dp" - android:layout_height="50dp" - android:layout_gravity="center_vertical" + android:id="@+id/notif_icon_image" + android:layout_width="50dp" + android:layout_height="50dp" + android:adjustViewBounds="false" + android:src="@drawable/notif_survey" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/msg_content_layout" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:layout_conversion_absoluteHeight="50dp" + tools:layout_conversion_absoluteWidth="50dp" + tools:srcCompat="@tools:sample/avatars"/> + <LinearLayout + android:id="@+id/msg_content_layout" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_marginTop="8dp" + android:orientation="vertical" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/btn_isi_survey_polling" + app:layout_constraintStart_toEndOf="@id/notif_icon_image" + app:layout_constraintTop_toTopOf="parent"> + <TextView + android:id="@+id/notification_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingLeft="10dp" + android:fontFamily="@font/josefin_sans_bold" + android:text="notification_name" + android:textAppearance="@style/TextAppearance.AppCompat.Body2" + android:textSize="14sp" + tools:layout_conversion_absoluteHeight="19dp" + tools:layout_conversion_absoluteWidth="260dp" + tools:layout_editor_absoluteX="60dp" + tools:layout_editor_absoluteY="19dp"/> + <TextView + android:id="@+id/notification_detail" + android:textStyle="bold" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingLeft="10dp" + android:fontFamily="@font/josefin_sans_thin" + android:text="notification_details" + android:textAppearance="@style/TextAppearance.AppCompat.Body1" + tools:layout_conversion_absoluteHeight="19dp" + tools:layout_conversion_absoluteWidth="260dp" + tools:layout_editor_absoluteX="60dp" + tools:layout_editor_absoluteY="38dp"/> + </LinearLayout> - tools:srcCompat="@tools:sample/avatars" /> + <Button + android:id="@+id/btn_isi_survey_polling" + android:layout_width="100dp" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:padding="@dimen/activity_horizontal_margin" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:fontFamily="@font/josefin_sans_bold" + android:text="@string/isi_survey_polling" + android:textAllCaps="false" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@id/msg_content_layout" + app:layout_constraintTop_toTopOf="parent" + tools:layout_conversion_absoluteHeight="48dp" + tools:layout_conversion_absoluteWidth="82dp"/> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> + </androidx.constraintlayout.widget.ConstraintLayout> - <TextView - android:id="@+id/textView2" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="9dp" - android:paddingLeft="10dp" - android:text="notification_name" /> - <TextView - android:id="@+id/textView3" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingLeft="10dp" - android:text="notification_details" /></LinearLayout> </LinearLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/notification_page.xml b/app/src/main/res/layout/notification_page.xml index ccd63500b726c44f5704ee65f147fed2316e700c..085e89f9718fb19b61b727a64514b68eee2e59cc 100644 --- a/app/src/main/res/layout/notification_page.xml +++ b/app/src/main/res/layout/notification_page.xml @@ -7,11 +7,9 @@ <androidx.recyclerview.widget.RecyclerView - android:layout_width="395dp" - android:layout_height="715dp" - android:layout_marginBottom="731dp" - android:layout_marginEnd="411dp" - android:layout_marginRight="411dp" + android:id="@+id/rv_notifications" + android:layout_width="0dp" + android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aeb2c6417be558f729e38ceecb85b9af64a51eca..f89ba5d5c308390426b61d935d6388c776031a61 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,4 +23,5 @@ <string name="title_pesan">Pesan</string> <string name="title_akun">Akun</string> <string name="title_beranda">Beranda</string> + <string name="isi_survey_polling">Isi</string> </resources>