├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_home.xml │ │ │ │ ├── ic_school.xml │ │ │ │ ├── ic_email.xml │ │ │ │ ├── ic_name.xml │ │ │ │ ├── ic_password.xml │ │ │ │ ├── ic_users.xml │ │ │ │ ├── ic_settings.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ │ ├── users_fragment.xml │ │ │ │ ├── activity_profile.xml │ │ │ │ ├── recyclerview_users.xml │ │ │ │ ├── home_fragment.xml │ │ │ │ ├── activity_login.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── settings_fragment.xml │ │ │ ├── menu │ │ │ │ └── bottom_menu.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── net │ │ │ │ └── simplifiedcoding │ │ │ │ └── retrofitandroidtutorial │ │ │ │ ├── models │ │ │ │ ├── UsersResponse.java │ │ │ │ ├── DefaultResponse.java │ │ │ │ ├── LoginResponse.java │ │ │ │ └── User.java │ │ │ │ ├── fragments │ │ │ │ ├── HomeFragment.java │ │ │ │ ├── UsersFragment.java │ │ │ │ └── SettingsFragment.java │ │ │ │ ├── api │ │ │ │ ├── Api.java │ │ │ │ └── RetrofitClient.java │ │ │ │ ├── adapters │ │ │ │ └── UsersAdapter.java │ │ │ │ ├── storage │ │ │ │ └── SharedPrefManager.java │ │ │ │ └── activities │ │ │ │ ├── ProfileActivity.java │ │ │ │ ├── LoginActivity.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── net │ │ │ └── simplifiedcoding │ │ │ └── retrofitandroidtutorial │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── net │ │ └── simplifiedcoding │ │ └── retrofitandroidtutorial │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── vcs.xml ├── runConfigurations.xml ├── gradle.xml ├── misc.xml ├── codeStyles │ └── Project.xml └── assetWizardSettings.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Retrofit Android Tutorial 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probelalkhan/Retrofit-Android-Tutorial/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jul 18 09:51:41 IST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #21a7ed 4 | #0a5b85 5 | #0886c7 6 | #375290 7 | #e4e4e4 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_home.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_school.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_email.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/users_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_name.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/net/simplifiedcoding/retrofitandroidtutorial/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_password.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/models/UsersResponse.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.models; 2 | 3 | import java.util.List; 4 | 5 | public class UsersResponse { 6 | 7 | private boolean error; 8 | private List users; 9 | 10 | public UsersResponse(boolean error, List users) { 11 | this.error = error; 12 | this.users = users; 13 | } 14 | 15 | public boolean isError() { 16 | return error; 17 | } 18 | 19 | public List getUsers() { 20 | return users; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/menu/bottom_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 18 | 19 | 20 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/models/DefaultResponse.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.models; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | public class DefaultResponse { 6 | 7 | @SerializedName("error") 8 | private boolean err; 9 | 10 | @SerializedName("message") 11 | private String msg; 12 | 13 | public DefaultResponse(boolean err, String msg) { 14 | this.err = err; 15 | this.msg = msg; 16 | } 17 | 18 | public boolean isErr() { 19 | return err; 20 | } 21 | 22 | public String getMsg() { 23 | return msg; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_users.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/models/LoginResponse.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.models; 2 | 3 | public class LoginResponse { 4 | 5 | private boolean error; 6 | private String message; 7 | private User user; 8 | 9 | public LoginResponse(boolean error, String message, User user) { 10 | this.error = error; 11 | this.message = message; 12 | this.user = user; 13 | } 14 | 15 | public boolean isError() { 16 | return error; 17 | } 18 | 19 | public String getMessage() { 20 | return message; 21 | } 22 | 23 | public User getUser() { 24 | return user; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/models/User.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.models; 2 | 3 | public class User { 4 | 5 | private int id; 6 | private String email, name, school; 7 | 8 | public User(int id, String email, String name, String school) { 9 | this.id = id; 10 | this.email = email; 11 | this.name = name; 12 | this.school = school; 13 | } 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public String getEmail() { 20 | return email; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public String getSchool() { 28 | return school; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/net/simplifiedcoding/retrofitandroidtutorial/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("net.simplifiedcoding.retrofitandroidtutorial", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_profile.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "net.simplifiedcoding.retrofitandroidtutorial" 7 | minSdkVersion 15 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:27.1.1' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | implementation 'com.squareup.retrofit2:retrofit:2.4.0' 29 | implementation 'com.squareup.retrofit2:converter-gson:2.4.0' 30 | implementation 'com.android.support:design:27.1.1' 31 | implementation 'com.android.support:cardview-v7:27.1.1' 32 | implementation 'com.android.support:recyclerview-v7:27.1.1' 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/fragments/HomeFragment.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.fragments; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TextView; 11 | 12 | import net.simplifiedcoding.retrofitandroidtutorial.R; 13 | import net.simplifiedcoding.retrofitandroidtutorial.storage.SharedPrefManager; 14 | 15 | public class HomeFragment extends Fragment { 16 | 17 | private TextView textViewEmail, textViewName, textViewSchool; 18 | 19 | @Nullable 20 | @Override 21 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 22 | return inflater.inflate(R.layout.home_fragment, container, false); 23 | } 24 | 25 | @Override 26 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 27 | super.onViewCreated(view, savedInstanceState); 28 | 29 | textViewEmail = view.findViewById(R.id.textViewEmail); 30 | textViewName = view.findViewById(R.id.textViewName); 31 | textViewSchool = view.findViewById(R.id.textViewSchool); 32 | 33 | textViewEmail.setText(SharedPrefManager.getInstance(getActivity()).getUser().getEmail()); 34 | textViewName.setText(SharedPrefManager.getInstance(getActivity()).getUser().getName()); 35 | textViewSchool.setText(SharedPrefManager.getInstance(getActivity()).getUser().getSchool()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recyclerview_users.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 16 | 17 | 23 | 24 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/api/Api.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.api; 2 | 3 | import net.simplifiedcoding.retrofitandroidtutorial.models.DefaultResponse; 4 | import net.simplifiedcoding.retrofitandroidtutorial.models.LoginResponse; 5 | import net.simplifiedcoding.retrofitandroidtutorial.models.UsersResponse; 6 | 7 | import retrofit2.Call; 8 | import retrofit2.http.DELETE; 9 | import retrofit2.http.Field; 10 | import retrofit2.http.FormUrlEncoded; 11 | import retrofit2.http.GET; 12 | import retrofit2.http.POST; 13 | import retrofit2.http.PUT; 14 | import retrofit2.http.Path; 15 | 16 | public interface Api { 17 | 18 | 19 | @FormUrlEncoded 20 | @POST("createuser") 21 | Call createUser( 22 | @Field("email") String email, 23 | @Field("password") String password, 24 | @Field("name") String name, 25 | @Field("school") String school 26 | ); 27 | 28 | @FormUrlEncoded 29 | @POST("userlogin") 30 | Call userLogin( 31 | @Field("email") String email, 32 | @Field("password") String password 33 | ); 34 | 35 | @GET("allusers") 36 | Call getUsers(); 37 | 38 | @FormUrlEncoded 39 | @PUT("updateuser/{id}") 40 | Call updateUser( 41 | @Path("id") int id, 42 | @Field("email") String email, 43 | @Field("name") String name, 44 | @Field("school") String school 45 | ); 46 | 47 | @FormUrlEncoded 48 | @PUT("updatepassword") 49 | Call updatePassword( 50 | @Field("currentpassword") String currentpassword, 51 | @Field("newpassword") String newpassword, 52 | @Field("email") String email 53 | ); 54 | 55 | @DELETE("deleteuser/{id}") 56 | Call deleteUser(@Path("id") int id); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /.idea/assetWizardSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/adapters/UsersAdapter.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.adapters; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import net.simplifiedcoding.retrofitandroidtutorial.R; 12 | import net.simplifiedcoding.retrofitandroidtutorial.models.User; 13 | 14 | import java.util.List; 15 | 16 | public class UsersAdapter extends RecyclerView.Adapter { 17 | 18 | private Context mCtx; 19 | private List userList; 20 | 21 | public UsersAdapter(Context mCtx, List userList) { 22 | this.mCtx = mCtx; 23 | this.userList = userList; 24 | } 25 | 26 | @NonNull 27 | @Override 28 | public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 29 | View view = LayoutInflater.from(mCtx).inflate(R.layout.recyclerview_users, parent, false); 30 | return new UsersViewHolder(view); 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(@NonNull UsersViewHolder holder, int position) { 35 | User user = userList.get(position); 36 | 37 | holder.textViewName.setText(user.getName()); 38 | holder.textViewEmail.setText(user.getEmail()); 39 | holder.textViewSchool.setText(user.getSchool()); 40 | } 41 | 42 | @Override 43 | public int getItemCount() { 44 | return userList.size(); 45 | } 46 | 47 | class UsersViewHolder extends RecyclerView.ViewHolder { 48 | 49 | TextView textViewName, textViewEmail, textViewSchool; 50 | 51 | public UsersViewHolder(View itemView) { 52 | super(itemView); 53 | 54 | textViewName = itemView.findViewById(R.id.textViewName); 55 | textViewEmail = itemView.findViewById(R.id.textViewEmail); 56 | textViewSchool = itemView.findViewById(R.id.textViewSchool); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/api/RetrofitClient.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.api; 2 | 3 | import android.util.Base64; 4 | 5 | import java.io.IOException; 6 | 7 | import okhttp3.Interceptor; 8 | import okhttp3.OkHttpClient; 9 | import okhttp3.Request; 10 | import okhttp3.Response; 11 | import retrofit2.Retrofit; 12 | import retrofit2.converter.gson.GsonConverterFactory; 13 | 14 | public class RetrofitClient { 15 | 16 | private static final String AUTH = "Basic " + Base64.encodeToString(("belalkhan:123456").getBytes(), Base64.NO_WRAP); 17 | 18 | private static final String BASE_URL = "http://simplifiedlabs.xyz/MyApi/public/"; 19 | private static RetrofitClient mInstance; 20 | private Retrofit retrofit; 21 | 22 | 23 | private RetrofitClient() { 24 | OkHttpClient okHttpClient = new OkHttpClient.Builder() 25 | .addInterceptor( 26 | new Interceptor() { 27 | @Override 28 | public Response intercept(Chain chain) throws IOException { 29 | Request original = chain.request(); 30 | 31 | Request.Builder requestBuilder = original.newBuilder() 32 | .addHeader("Authorization", AUTH) 33 | .method(original.method(), original.body()); 34 | 35 | Request request = requestBuilder.build(); 36 | return chain.proceed(request); 37 | } 38 | } 39 | ).build(); 40 | 41 | retrofit = new Retrofit.Builder() 42 | .baseUrl(BASE_URL) 43 | .addConverterFactory(GsonConverterFactory.create()) 44 | .client(okHttpClient) 45 | .build(); 46 | } 47 | 48 | public static synchronized RetrofitClient getInstance() { 49 | if (mInstance == null) { 50 | mInstance = new RetrofitClient(); 51 | } 52 | return mInstance; 53 | } 54 | 55 | public Api getApi() { 56 | return retrofit.create(Api.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/storage/SharedPrefManager.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.storage; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import net.simplifiedcoding.retrofitandroidtutorial.models.User; 7 | 8 | public class SharedPrefManager { 9 | 10 | private static final String SHARED_PREF_NAME = "my_shared_preff"; 11 | 12 | private static SharedPrefManager mInstance; 13 | private Context mCtx; 14 | 15 | private SharedPrefManager(Context mCtx) { 16 | this.mCtx = mCtx; 17 | } 18 | 19 | 20 | public static synchronized SharedPrefManager getInstance(Context mCtx) { 21 | if (mInstance == null) { 22 | mInstance = new SharedPrefManager(mCtx); 23 | } 24 | return mInstance; 25 | } 26 | 27 | 28 | public void saveUser(User user) { 29 | 30 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 31 | SharedPreferences.Editor editor = sharedPreferences.edit(); 32 | 33 | editor.putInt("id", user.getId()); 34 | editor.putString("email", user.getEmail()); 35 | editor.putString("name", user.getName()); 36 | editor.putString("school", user.getSchool()); 37 | 38 | editor.apply(); 39 | 40 | } 41 | 42 | public boolean isLoggedIn() { 43 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 44 | return sharedPreferences.getInt("id", -1) != -1; 45 | } 46 | 47 | public User getUser() { 48 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 49 | return new User( 50 | sharedPreferences.getInt("id", -1), 51 | sharedPreferences.getString("email", null), 52 | sharedPreferences.getString("name", null), 53 | sharedPreferences.getString("school", null) 54 | ); 55 | } 56 | 57 | public void clear() { 58 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 59 | SharedPreferences.Editor editor = sharedPreferences.edit(); 60 | editor.clear(); 61 | editor.apply(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/fragments/UsersFragment.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.fragments; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import net.simplifiedcoding.retrofitandroidtutorial.R; 14 | import net.simplifiedcoding.retrofitandroidtutorial.adapters.UsersAdapter; 15 | import net.simplifiedcoding.retrofitandroidtutorial.api.RetrofitClient; 16 | import net.simplifiedcoding.retrofitandroidtutorial.models.User; 17 | import net.simplifiedcoding.retrofitandroidtutorial.models.UsersResponse; 18 | 19 | import java.util.List; 20 | 21 | import retrofit2.Call; 22 | import retrofit2.Callback; 23 | import retrofit2.Response; 24 | 25 | public class UsersFragment extends Fragment { 26 | 27 | private RecyclerView recyclerView; 28 | private UsersAdapter adapter; 29 | private List userList; 30 | 31 | @Nullable 32 | @Override 33 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 34 | return inflater.inflate(R.layout.users_fragment, container, false); 35 | } 36 | 37 | @Override 38 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 39 | super.onViewCreated(view, savedInstanceState); 40 | 41 | recyclerView = view.findViewById(R.id.recyclerView); 42 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 43 | 44 | 45 | Call call = RetrofitClient.getInstance().getApi().getUsers(); 46 | 47 | call.enqueue(new Callback() { 48 | @Override 49 | public void onResponse(Call call, Response response) { 50 | 51 | userList = response.body().getUsers(); 52 | adapter = new UsersAdapter(getActivity(), userList); 53 | recyclerView.setAdapter(adapter); 54 | } 55 | 56 | @Override 57 | public void onFailure(Call call, Throwable t) { 58 | 59 | } 60 | }); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/home_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 55 | 56 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/net/simplifiedcoding/retrofitandroidtutorial/activities/ProfileActivity.java: -------------------------------------------------------------------------------- 1 | package net.simplifiedcoding.retrofitandroidtutorial.activities; 2 | 3 | import android.content.Intent; 4 | import android.support.annotation.NonNull; 5 | import android.support.design.widget.BottomNavigationView; 6 | import android.support.design.widget.NavigationView; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.view.MenuItem; 11 | import android.widget.TextView; 12 | 13 | import net.simplifiedcoding.retrofitandroidtutorial.R; 14 | import net.simplifiedcoding.retrofitandroidtutorial.fragments.HomeFragment; 15 | import net.simplifiedcoding.retrofitandroidtutorial.fragments.SettingsFragment; 16 | import net.simplifiedcoding.retrofitandroidtutorial.fragments.UsersFragment; 17 | import net.simplifiedcoding.retrofitandroidtutorial.models.User; 18 | import net.simplifiedcoding.retrofitandroidtutorial.storage.SharedPrefManager; 19 | 20 | public class ProfileActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener { 21 | 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_profile); 27 | 28 | BottomNavigationView navigationView = findViewById(R.id.bottom_nav); 29 | navigationView.setOnNavigationItemSelectedListener(this); 30 | 31 | displayFragment(new HomeFragment()); 32 | } 33 | 34 | private void displayFragment(Fragment fragment) { 35 | getSupportFragmentManager() 36 | .beginTransaction() 37 | .replace(R.id.relativeLayout, fragment) 38 | .commit(); 39 | } 40 | 41 | 42 | @Override 43 | protected void onStart() { 44 | super.onStart(); 45 | 46 | if (!SharedPrefManager.getInstance(this).isLoggedIn()) { 47 | Intent intent = new Intent(this, MainActivity.class); 48 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 49 | startActivity(intent); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 55 | 56 | Fragment fragment = null; 57 | 58 | switch(item.getItemId()){ 59 | case R.id.menu_home: 60 | fragment = new HomeFragment(); 61 | break; 62 | case R.id.menu_users: 63 | fragment = new UsersFragment(); 64 | break; 65 | case R.id.menu_settings: 66 | fragment = new SettingsFragment(); 67 | break; 68 | } 69 | 70 | if(fragment != null){ 71 | displayFragment(fragment); 72 | } 73 | 74 | return false; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 30 | 31 | 39 | 40 | 48 | 49 | 50 | 51 | 52 | 64 | 65 |