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

Student list activity #31

Merged
merged 2 commits into from Dec 19, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions app/build.gradle
Expand Up @@ -47,28 +47,28 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v13:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0-rc01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-rc01'
implementation 'androidx.browser:browser:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.constraintlayout:constraintlayout-solver:1.1.2'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0-rc01'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout-solver:1.1.3'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.facebook.fresco:fresco:1.10.0'
implementation 'com.facebook.fresco:webpsupport:1.9.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.16'
implementation 'me.relex:photodraweeview:1.1.3'
implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'com.github.gcacace:signature-pad:1.2.1'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
def lifecycle_version = "2.0.0-rc01"
def lifecycle_version = "2.0.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -14,7 +14,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:largeHeap="true">

<activity android:name=".activities.HomeActivity">

Expand Down Expand Up @@ -55,6 +56,9 @@

<activity android:name=".activities.LoginActivity">
</activity>

<activity android:name=".activities.ResidentActivity">
</activity>
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="barcode" />
Expand Down
Expand Up @@ -54,7 +54,6 @@ protected void onCreate(Bundle savedInstanceState) {

String password;
String prdrive_id;

Button logout_btn;

Realm.init(HomeActivity.this);
Expand Down
@@ -1,5 +1,6 @@
package com.macbitsgoa.prdrive.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -17,10 +18,16 @@
import static com.macbitsgoa.prdrive.StaticHelperClass.finishbtn;
public class MerchActivity extends AppCompatActivity {

// TODO: add necessary arguments to be passed via intent
public static void launchMerch(Context context) {
Intent intent = new Intent(context, MerchActivity.class);
context.startActivity(intent);
}

@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
androidx.appcompat.widget.Toolbar toolbar = null;
androidx.appcompat.widget.Toolbar toolbar;
RecyclerView rv;
setContentView(R.layout.activity_merch);
//Setting up the Finish order button.
Expand Down Expand Up @@ -69,7 +76,3 @@ protected void onCreate (Bundle savedInstanceState) {
}

}




@@ -0,0 +1,44 @@
package com.macbitsgoa.prdrive.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.adapters.ResidentAdapter;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


public class ResidentActivity extends Activity {

public static final String INTENT_KEY_HOSTEL_NAME = ResidentActivity.class.getName() + ".intent.hostelName";

/**
* Use this method to launch this activity correctly.
*
* @param parent from which this is to be launched.
* @param hostelName name of the target hostel.
*/
public static void launchHostel(Context parent, String hostelName) {
Intent intent = new Intent(parent, ResidentActivity.class);
intent.putExtra(INTENT_KEY_HOSTEL_NAME, hostelName);
parent.startActivity(intent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resident);

Intent source = getIntent();
final String hostelName = source.getStringExtra(INTENT_KEY_HOSTEL_NAME);
RecyclerView rv;
rv = findViewById(R.id.list_rv);
rv.setLayoutManager(new LinearLayoutManager(ResidentActivity.this));
ResidentAdapter residentAdapter = new ResidentAdapter(hostelName);
rv.setAdapter(residentAdapter);
}
}
34 changes: 25 additions & 9 deletions app/src/main/java/com/macbitsgoa/prdrive/adapters/HomeAdapter.java
@@ -1,37 +1,53 @@
package com.macbitsgoa.prdrive.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.Student;
import com.macbitsgoa.prdrive.viewholders.HomeViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import io.realm.Realm;
import io.realm.RealmQuery;
import io.realm.RealmResults;


public class HomeAdapter extends RecyclerView.Adapter<HomeViewHolder> {


private String hostelNames[] = {"AH1", "AH2", "AH3", "AH4", "AH5", "AH6", "AH7",
"AH8", "AH9", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "DH1", "DH2"};


private List<String> hostelNames;

public HomeAdapter() {
hostelNames = new ArrayList<>();
Realm realm = Realm.getDefaultInstance();
RealmQuery<Student> query = realm.where(Student.class).distinct("hostel");
RealmResults<Student> results = query.findAll();
for (Student s : results) {
hostelNames.add(s.hostel);
}
realm.close();
}

@NonNull
@Override
public HomeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new HomeViewHolder(View.inflate(parent.getContext(), R.layout.item_format_home, null),
parent.getContext());
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_format_home, parent, false);
return new HomeViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull HomeViewHolder holder, int position) {
holder.populate(hostelNames[position]);
holder.populate(hostelNames.get(position));
}

@Override
public int getItemCount() {
return hostelNames.length;
return hostelNames.size();
}
}
@@ -0,0 +1,45 @@
package com.macbitsgoa.prdrive.adapters;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.Student;
import com.macbitsgoa.prdrive.viewholders.ResidentViewHolder;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import io.realm.Realm;
import io.realm.RealmQuery;
import io.realm.RealmResults;

public class ResidentAdapter extends RecyclerView.Adapter<ResidentViewHolder> {

private List<Student> students;

public ResidentAdapter(String hostel) {
Realm realm = Realm.getDefaultInstance();
RealmQuery<Student> query = realm.where(Student.class).equalTo("hostel", hostel);
RealmResults<Student> results = query.findAll();
students = realm.copyFromRealm(results);
realm.close();
}

@Override
public ResidentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ResidentViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_format_resident, parent, false));
}

@Override
public void onBindViewHolder(@NonNull ResidentViewHolder holder, int position) {
holder.populate(students.get(position));
}

@Override
public int getItemCount() {
return students.size();
}
}
@@ -1,8 +1,5 @@
package com.macbitsgoa.prdrive.viewholders;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
Expand All @@ -15,37 +12,32 @@
import com.google.firebase.database.ValueEventListener;
import com.macbitsgoa.prdrive.BuildConfig;
import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.activities.MerchActivity;

import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import static com.macbitsgoa.prdrive.StaticHelperClass.hostelname;

public class HomeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
import static com.macbitsgoa.prdrive.activities.ResidentActivity.launchHostel;

private TextView hostelName;
private Context context;
private Activity activity;
private DatabaseReference databaseReference = FirebaseDatabase
.getInstance().getReference().child(BuildConfig.BUILD_TYPE).child("main").child("orgInfo").child("prdrive-meta");
public class HomeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private TextView hostelNameTv;
private DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child(BuildConfig.BUILD_TYPE)
.child("main").child("orgInfo").child("prdrive-meta");
private CardView cardView;

public HomeViewHolder(View itemView, Context context) {

public HomeViewHolder(View itemView) {
super(itemView);
CardView cardView;
this.context = context;
this.activity = (Activity) this.context;
hostelName = itemView.findViewById(R.id.ifhometv);
hostelNameTv = itemView.findViewById(R.id.ifhometv);
cardView = itemView.findViewById(R.id.ifhomecard);
cardView.setOnClickListener(this);

}

public void populate(@NonNull final String str) {
hostelName.setText(str);
public void populate(@NonNull final String hostel) {
hostelNameTv.setText(hostel);
cardView.setOnClickListener(this);
}

@Override
Expand All @@ -56,19 +48,17 @@ public void onClick(View view) {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.e("data1", dataSnapshot.getKey());
for (DataSnapshot child: dataSnapshot.getChildren()) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Log.e("data1", child.getKey());
killSwitch[0] = Objects.requireNonNull(child.child("killSwitch").getValue(String.class));
}
if (killSwitch[0].equals("1")) {
Intent intent = new Intent(context, MerchActivity.class);
hostelname = hostelName.getText().toString();
context.startActivity(intent);
activity.finish();
}
else {
String hostelName = hostelNameTv.getText().toString();
launchHostel(itemView.getContext(), hostelName);
//activity.finish();
} else {
//activity.finish();
Toast.makeText(context, "not allowed", Toast.LENGTH_SHORT).show();
Toast.makeText(itemView.getContext(), "not allowed", Toast.LENGTH_SHORT).show();
}
}

Expand All @@ -77,7 +67,7 @@ public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
Log.e("data", ""+killSwitch[0]);
Log.e("data", "" + killSwitch[0]);

}
}
@@ -0,0 +1,36 @@
package com.macbitsgoa.prdrive.viewholders;

import android.view.View;
import android.widget.TextView;

import com.macbitsgoa.prdrive.R;
import com.macbitsgoa.prdrive.Student;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import static com.macbitsgoa.prdrive.activities.MerchActivity.launchMerch;


public class ResidentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

public TextView nameTv;
public TextView roomNoTv;

public ResidentViewHolder(@NonNull View itemView) {
super(itemView);
nameTv = itemView.findViewById(R.id.tv_name);
roomNoTv = itemView.findViewById(R.id.tv_room_no);
}

public void populate(Student student) {
nameTv.setText(student.name);
roomNoTv.setText(student.roomNo);
itemView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
launchMerch(itemView.getContext());
}
}