Skip to content

Commit 3a0200b

Browse files
authored
Merge pull request #6 from mob-developer/7-add-profile-picture
7 add profile picture
2 parents 80f6da5 + db28ca3 commit 3a0200b

File tree

9 files changed

+112
-27
lines changed

9 files changed

+112
-27
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/ir/mk/learnx/Home.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package ir.mk.learnx;
22

3+
import androidx.appcompat.app.AlertDialog;
34
import androidx.appcompat.app.AppCompatActivity;
45
import androidx.recyclerview.widget.LinearLayoutManager;
56
import androidx.recyclerview.widget.RecyclerView;
67

78
import android.annotation.SuppressLint;
9+
import android.content.DialogInterface;
810
import android.content.Intent;
911
import android.content.SharedPreferences;
12+
import android.net.Uri;
1013
import android.os.Bundle;
1114
import android.widget.Button;
15+
import android.widget.ImageView;
1216
import android.widget.TextView;
1317

1418
import java.util.ArrayList;
1519

1620
import ir.mk.learnx.adapters.HomeCourseListAdapter;
1721
import ir.mk.learnx.login.LandingPageActivity;
18-
import ir.mk.learnx.login.LoginActivity;
1922
import ir.mk.learnx.model.Account;
2023
import ir.mk.learnx.model.CourseList;
2124
import ir.mk.learnx.model.Server;
25+
import ir.mk.learnx.quiz.QuizActivity;
2226
import ir.mk.learnx.quiz.QuizListActivity;
2327

2428

@@ -47,6 +51,12 @@ protected void onCreate(Bundle savedInstanceState) {
4751
recyclerView.setLayoutManager(new LinearLayoutManager(this));
4852
recyclerView.setAdapter(homeCourseListAdapter);
4953

54+
Button exit = findViewById(R.id.exit);
55+
exit.setOnClickListener(v -> {
56+
Account.setLoggedInAccount(null);
57+
Intent i = new Intent(Home.this, LandingPageActivity.class);
58+
startActivity(i);
59+
});
5060

5161
Button quizButton = findViewById(R.id.button_quiz);
5262
quizButton.setOnClickListener(v -> {
@@ -67,15 +77,33 @@ protected void onCreate(Bundle savedInstanceState) {
6777
scoreText.setText(String.valueOf(iq));
6878

6979
TextView nameText = findViewById(R.id.textView5);
70-
nameText.setText(Account.getLoggedInAccount().getFirstName() + " " + Account.getLoggedInAccount().getLastName());
80+
nameText.setText(Account.getLoggedInAccount().getLastName() + " " + Account.getLoggedInAccount().getFirstName());
81+
7182

83+
ImageView profilePicture = findViewById(R.id.imageView3);
84+
if (!Account.getLoggedInAccount().getProfilePictureUri().equals(Uri.EMPTY))
85+
profilePicture.setImageURI(Account.getLoggedInAccount().getProfilePictureUri());
7286

7387

7488
}
89+
7590
@Override
7691
public void onBackPressed() {
77-
Intent i = new Intent(Home.this, LandingPageActivity.class);
78-
startActivity(i);
92+
if (Account.getLoggedInAccount() == null) {
93+
Intent i = new Intent(Home.this, LandingPageActivity.class);
94+
startActivity(i);
95+
} else {
96+
new AlertDialog.Builder(this)
97+
.setTitle("خروج")
98+
.setMessage("آیا می خواهید از برنامه خارج شوید؟")
99+
.setNegativeButton("خیر", null)
100+
.setPositiveButton("بله", new DialogInterface.OnClickListener() {
101+
102+
public void onClick(DialogInterface arg0, int arg1) {
103+
android.os.Process.killProcess(android.os.Process.myPid());
104+
}
105+
}).create().show();
106+
}
79107
}
80108

81109
}

app/src/main/java/ir/mk/learnx/login/LandingPageActivity.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ public void onBackPressed() {
5757

5858
this.doubleBackToExitPressedOnce = true;
5959

60-
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
61-
62-
@Override
63-
public void run() {
64-
doubleBackToExitPressedOnce=false;
65-
}
66-
}, 3000);
60+
new Handler(Looper.getMainLooper()).postDelayed(() -> doubleBackToExitPressedOnce=false, 3000);
6761
}
6862

6963
}

app/src/main/java/ir/mk/learnx/login/SignUpActivity.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
import androidx.appcompat.app.AppCompatActivity;
44

55
import android.content.Intent;
6+
import android.net.Uri;
67
import android.os.Bundle;
78
import android.widget.Button;
89
import android.widget.EditText;
10+
import android.widget.ImageView;
911
import android.widget.Toast;
1012

13+
import com.bumptech.glide.Glide;
14+
1115
import ir.mk.learnx.R;
1216
import ir.mk.learnx.model.Account;
1317

1418
public class SignUpActivity extends AppCompatActivity {
19+
private static final int SELECT_PICTURE = 100;
20+
private static ImageView imageView;
21+
private Uri profilePictureUri;
1522

1623
@Override
1724
protected void onCreate(Bundle savedInstanceState) {
@@ -23,15 +30,22 @@ protected void onCreate(Bundle savedInstanceState) {
2330
EditText passwordField = findViewById(R.id.sign_up_password_field);
2431
EditText firstNameField = findViewById(R.id.sign_up_first_name);
2532
EditText lastNameField = findViewById(R.id.sign_up_last_name);
33+
imageView = findViewById(R.id.sign_up_profile_picture);
34+
imageView.setOnClickListener(v -> {
35+
openImageChooser();
36+
});
37+
2638

2739
button.setOnClickListener(v -> {
2840
if (!usernameField.getText().toString().isEmpty() && !emailField.getText().toString().isEmpty() &&
2941
!passwordField.getText().toString().isEmpty() && !firstNameField.getText().toString().isEmpty() &&
3042
!lastNameField.getText().toString().isEmpty()) {
3143
new Account(firstNameField.getText().toString(), lastNameField.getText().toString(),
3244
0, 0, usernameField.getText().toString(),
33-
passwordField.getText().toString(), emailField.getText().toString(), 0);
45+
passwordField.getText().toString(), emailField.getText().toString(), 0,
46+
profilePictureUri);
3447
Toast.makeText(this, "حساب کاربری با موفقیت ساخته شد", Toast.LENGTH_LONG).show();
48+
Intent i = new Intent(SignUpActivity.this, LandingPageActivity.class);
3549
} else {
3650
Toast.makeText(this, "خطایی رخ داده است دوباره تلاش کنید", Toast.LENGTH_LONG).show();
3751
}
@@ -46,4 +60,26 @@ public void onBackPressed() {
4660
Intent i = new Intent(SignUpActivity.this, LandingPageActivity.class);
4761
startActivity(i);
4862
}
63+
64+
public void openImageChooser() {
65+
Intent intent = new Intent();
66+
intent.setType("image/*");
67+
intent.setAction(Intent.ACTION_GET_CONTENT);
68+
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
69+
}
70+
71+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
72+
super.onActivityResult(requestCode, resultCode, data);
73+
if (resultCode == RESULT_OK) {
74+
if (requestCode == SELECT_PICTURE) {
75+
Uri selectedImageUri = data.getData();
76+
if (selectedImageUri != null) {
77+
imageView.setImageURI(null);
78+
imageView.setImageURI(selectedImageUri);
79+
imageView.setCropToPadding(true);
80+
this.profilePictureUri = selectedImageUri;
81+
}
82+
}
83+
}
84+
}
4985
}

app/src/main/java/ir/mk/learnx/model/Account.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ir.mk.learnx.model;
22

3+
import android.net.Uri;
4+
35
import java.util.ArrayList;
46

57
public class Account {
@@ -13,9 +15,10 @@ public class Account {
1315
private final String username;
1416
private final String password;
1517
private final String email;
18+
private final Uri profilePictureUri;
1619
private int score;
1720

18-
public Account(String firstName, String lastName, int age, int phoneNumber, String username, String password, String email, int score) {
21+
public Account(String firstName, String lastName, int age, int phoneNumber, String username, String password, String email, int score, Uri profilePictureUri) {
1922
this.firstName = firstName;
2023
this.lastName = lastName;
2124
this.age = age;
@@ -24,6 +27,7 @@ public Account(String firstName, String lastName, int age, int phoneNumber, Stri
2427
this.password = password;
2528
this.email = email;
2629
this.score = score;
30+
this.profilePictureUri = profilePictureUri;
2731
allAccount.add(this);
2832
}
2933

@@ -83,6 +87,10 @@ public void setScore(int score) {
8387

8488
public static Account getLoggedInAccount() {
8589
return loggedInAccount != null ? loggedInAccount : new Account("میهمان","",
86-
0,0,"","","",0);
90+
0,0,"","","",0, Uri.EMPTY);
91+
}
92+
93+
public Uri getProfilePictureUri() {
94+
return profilePictureUri;
8795
}
8896
}

app/src/main/java/ir/mk/learnx/teach/LearnQuizActivity.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ protected void onCreate(Bundle savedInstanceState) {
7676
loadingImageView = findViewById(R.id.learn_quiz_loading);
7777
Glide.with(this).load(R.mipmap.loading_gif).into(loadingImageView);
7878

79-
8079
Button report = findViewById(R.id.report);
8180
report.setOnClickListener(v -> {
8281
Toast.makeText(this, "گزارش شما با موفقیت ثبت شد", Toast.LENGTH_LONG).show();
@@ -92,9 +91,6 @@ protected void onCreate(Bundle savedInstanceState) {
9291
Toast.makeText(this, "نظر شما ثبت شد", Toast.LENGTH_LONG).show();
9392
});
9493

95-
96-
97-
9894
handler = new Handler() {
9995
@SuppressLint("HandlerLeak")
10096
@Override
@@ -164,8 +160,8 @@ public void run() {
164160
threadGetQuestion.start();
165161
}
166162

167-
private int getStepType(String allStep, int thisStep){
168-
return Integer.parseInt(allStep.substring(thisStep,thisStep+1));
163+
private int getStepType(String allStep, int thisStep) {
164+
return Integer.parseInt(allStep.substring(thisStep, thisStep + 1));
169165
}
170166

171167
private void showQuestion() {
@@ -200,7 +196,7 @@ private void showQuestion() {
200196
ConstraintLayout constraintLayout = findViewById(R.id.activity_question);
201197
constraintLayout.setOnClickListener(v -> {
202198
Toast.makeText(this, "view clicked!", Toast.LENGTH_SHORT).show();
203-
if (ended && !ended2){
199+
if (ended && !ended2) {
204200
ConstraintLayout constraintLayout1 = findViewById(R.id.quiz_end);
205201
constraintLayout1.setVisibility(View.VISIBLE);
206202
ended2 = true;
@@ -221,7 +217,7 @@ private void showQuestion() {
221217
}
222218
}
223219
}
224-
if (ended && !ended2){
220+
if (ended && !ended2) {
225221
ConstraintLayout constraintLayout1 = findViewById(R.id.quiz_end);
226222
constraintLayout1.setVisibility(View.VISIBLE);
227223
ended2 = true;
@@ -268,7 +264,6 @@ private String run(String url) throws IOException {
268264
}
269265

270266

271-
272267
@Override
273268
public void onBackPressed() {
274269
new AlertDialog.Builder(this)
@@ -278,9 +273,9 @@ public void onBackPressed() {
278273
.setPositiveButton("بله", new DialogInterface.OnClickListener() {
279274

280275
public void onClick(DialogInterface arg0, int arg1) {
281-
Intent intent = new Intent(LearnQuizActivity.this,SubCourseListActivity.class);
282-
intent.putExtra("lesson",lesson);
283-
intent.putExtra("courseId",courseId);
276+
Intent intent = new Intent(LearnQuizActivity.this, SubCourseListActivity.class);
277+
intent.putExtra("lesson", lesson);
278+
intent.putExtra("courseId", courseId);
284279
LearnQuizActivity.this.startActivity(intent);
285280
finish();
286281
}

app/src/main/res/layout/activity_home.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,25 @@
5252
android:layout_width="wrap_content"
5353
android:layout_height="wrap_content"
5454
android:layout_marginRight="10dp"
55+
android:gravity="center"
5556
android:text="۴۰۰"
5657
android:textColor="@color/white"
5758
app:layout_constraintBottom_toBottomOf="parent"
5859
app:layout_constraintEnd_toStartOf="@+id/textView9"
5960
app:layout_constraintTop_toBottomOf="@+id/textView5" />
6061

62+
<Button
63+
android:id="@+id/exit"
64+
android:layout_width="40dp"
65+
android:layout_height="40dp"
66+
android:padding="5dp"
67+
android:text="خروج"
68+
android:textSize="10sp"
69+
app:layout_constraintStart_toStartOf="parent"
70+
android:background="@color/red"
71+
android:visibility="gone"
72+
app:layout_constraintTop_toTopOf="parent" />
73+
6174

6275
</androidx.constraintlayout.widget.ConstraintLayout>
6376

app/src/main/res/layout/activity_sign_up.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
77
tools:context=".login.SignUpActivity">
8+
9+
<ImageView
10+
android:id="@+id/sign_up_profile_picture"
11+
android:layout_width="80dp"
12+
android:layout_height="80dp"
13+
android:background="@drawable/ic_baseline_account_circle_24"
14+
app:layout_constraintBottom_toTopOf="@+id/sign_up_email_field"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
818
<EditText
919
android:id="@+id/sign_up_email_field"
1020
android:layout_width="0dp"

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<color name="teal_white">#9FC5E3</color>
1111
<color name="back">#F6F6F6</color>
1212
<color name="main_green">#00D0AF</color>
13+
<color name="red">#FF0000</color>
1314
</resources>

0 commit comments

Comments
 (0)