| @@ -1,27 +1,31 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.icaboalo.tabsdrawerretrofitwithbutternife" > | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
|
|
||
| <application | ||
| android:allowBackup="true" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/AppTheme" > | ||
| <activity | ||
| android:name=".ui.activity.MainActivity" | ||
| android:label="@string/app_name" > | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity | ||
| android:name=".ui.activity.LogInActivity" | ||
| android:label="@string/title_activity_log_in" > | ||
| </activity> | ||
| <activity | ||
| android:name=".ui.activity.SignUpActivity" | ||
| android:label="@string/title_activity_sign_up" > | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> |
| @@ -1,28 +1,28 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.constants; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class CourseraConstants { | ||
| public static final String BASE_URL = "https://api.coursera.org/api/catalog.v1"; | ||
| public static final String PATH_COURSES = "/courses"; | ||
| public static final String ARG_TYPE = "q"; | ||
| public static final String VALUE_SEARCH = "search"; | ||
| public static final String ARG_FIELD = "fields"; | ||
| public static final String VALUE_SHORT_DESCRIPTION = "shortDescription"; | ||
| public static final String VALUE_PHOTO = "photo"; | ||
| public static final String ARG_QUERY = "query"; | ||
| public static final String URL_SEARCH_COURSE = | ||
| PATH_COURSES + | ||
| "?" + | ||
| ARG_TYPE + | ||
| "=" + | ||
| VALUE_SEARCH + | ||
| "&" + | ||
| ARG_FIELD + | ||
| "=" + | ||
| VALUE_SHORT_DESCRIPTION + | ||
| "," + | ||
| VALUE_PHOTO; | ||
|
|
||
| } |
| @@ -1,10 +1,12 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.constants; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/25/2015. | ||
| */ | ||
| public class PrefsConstants { | ||
| public static final String FILE_LOGIN = "LoginPrefs"; | ||
| public static final String PREF_USERNAME = "username"; | ||
| public static final String PREF_PASSWORD = "password"; | ||
| public static final String PREF_FIRST_NAME = "name"; | ||
| public static final String PREF_LAST_NAME = "last_name"; | ||
| } |
| @@ -1,9 +1,9 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.constants; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class UdacityConstants { | ||
| public static final String BASE_URL = "https://www.udacity.com/public-api/v0"; | ||
| public static final String PATH_COURSE = "/courses"; | ||
| } |
| @@ -1,38 +1,38 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.domain; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class CourseraModel { | ||
|
|
||
| @SerializedName("name") | ||
| String courseName; | ||
|
|
||
| @SerializedName("id") | ||
| String courseId; | ||
|
|
||
| @SerializedName("photo") | ||
| String courseImage; | ||
|
|
||
| @SerializedName("shortDescription") | ||
| String courseDescription; | ||
|
|
||
| public String getCourseName() { | ||
| return courseName; | ||
| } | ||
|
|
||
| public String getCourseId() { | ||
| return courseId; | ||
| } | ||
|
|
||
| public String getCourseImage() { | ||
|
|
||
| return courseImage; | ||
| } | ||
|
|
||
| public String getCourseDescription() { | ||
| return courseDescription; | ||
| } | ||
| } |
| @@ -1,24 +1,24 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.domain; | ||
|
|
||
| import android.support.v4.app.Fragment; | ||
|
|
||
| /** | ||
| * Created by LEONARDO on 25/09/2015. | ||
| */ | ||
| public class ModelFramentPager { | ||
| private Fragment pager; | ||
| private String title; | ||
|
|
||
| public ModelFramentPager(Fragment pager, String title) { | ||
| this.pager = pager; | ||
| this.title = title; | ||
| } | ||
|
|
||
| public Fragment getPager() { | ||
| return pager; | ||
| } | ||
|
|
||
| public String getTitle() { | ||
| return title; | ||
| } | ||
| } |
| @@ -1,37 +1,37 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.domain; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class UdacityModel { | ||
|
|
||
| @SerializedName("title") | ||
| String courseTitle; | ||
|
|
||
| @SerializedName("image") | ||
| String courseImage; | ||
|
|
||
| @SerializedName("short_summary") | ||
| String courseDescription; | ||
|
|
||
| @SerializedName("level") | ||
| String courseLevel; | ||
|
|
||
| public String getCourseTitle() { | ||
| return courseTitle; | ||
| } | ||
|
|
||
| public String getCourseImage() { | ||
| return courseImage; | ||
| } | ||
|
|
||
| public String getCourseDescription() { | ||
| return courseDescription; | ||
| } | ||
|
|
||
| public String getCourseLevel() { | ||
| return courseLevel; | ||
| } | ||
| } |
| @@ -1,53 +1,53 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.io; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.CourseraConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.UdacityConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchCourseraResponse; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchUdacityResponse; | ||
|
|
||
| import retrofit.Callback; | ||
| import retrofit.RestAdapter; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class ApiClient { | ||
|
|
||
| // udacity api | ||
| private static ApiService udacityApiService; | ||
|
|
||
| public static ApiService getUdacityApiService(){ | ||
| if (udacityApiService == null){ | ||
| RestAdapter restAdapter = new RestAdapter.Builder() | ||
| .setEndpoint(UdacityConstants.BASE_URL) | ||
| .setLogLevel(RestAdapter.LogLevel.BASIC) | ||
| .build(); | ||
| udacityApiService = restAdapter.create(ApiService.class); | ||
| } | ||
| return udacityApiService; | ||
| } | ||
|
|
||
| public static void searchUdacityCourse(Callback<SearchUdacityResponse> udacityApiResponse){ | ||
| getUdacityApiService().searchUdacityCourse(udacityApiResponse); | ||
| } | ||
|
|
||
|
|
||
| // coursera api | ||
| private static ApiService courseraApiService; | ||
| public static ApiService getCourseraApiService(){ | ||
| if (courseraApiService == null){ | ||
| RestAdapter restAdapter = new RestAdapter.Builder() | ||
| .setEndpoint(CourseraConstants.BASE_URL) | ||
| .setLogLevel(RestAdapter.LogLevel.BASIC) | ||
| .build(); | ||
| courseraApiService = restAdapter.create(ApiService.class); | ||
| } | ||
| return courseraApiService; | ||
| } | ||
|
|
||
| public static void searchCourseraCourse(String query, Callback<SearchCourseraResponse> courseraApiResponse){ | ||
| getCourseraApiService().searchCourseraCourse(query, courseraApiResponse); | ||
| } | ||
|
|
||
|
|
||
| } |
| @@ -1,21 +1,21 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.io; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.CourseraConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.UdacityConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchCourseraResponse; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchUdacityResponse; | ||
|
|
||
| import retrofit.Callback; | ||
| import retrofit.http.GET; | ||
| import retrofit.http.Query; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public interface ApiService { | ||
| @GET(UdacityConstants.PATH_COURSE) | ||
| void searchUdacityCourse(Callback<SearchUdacityResponse> udacityApiResposnse); | ||
|
|
||
| @GET(CourseraConstants.URL_SEARCH_COURSE) | ||
| void searchCourseraCourse(@Query(CourseraConstants.ARG_QUERY)String course, Callback<SearchCourseraResponse> courseraApiResponse); | ||
| } |
| @@ -1,19 +1,19 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.io.model; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.CourseraModel; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class SearchCourseraResponse { | ||
|
|
||
| @SerializedName("elements") | ||
| ArrayList<CourseraModel> courseList; | ||
|
|
||
| public ArrayList<CourseraModel> getCourseList() { | ||
| return courseList; | ||
| } | ||
| } |
| @@ -1,19 +1,19 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.io.model; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.UdacityModel; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class SearchUdacityResponse { | ||
|
|
||
| @SerializedName("courses") | ||
| ArrayList<UdacityModel> courses; | ||
|
|
||
| public ArrayList<UdacityModel> getCourses() { | ||
| return courses; | ||
| } | ||
| } |
| @@ -1,44 +1,60 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite.Constants; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class DbConstants { | ||
| public static final int DATABASE_VERSION = 1; | ||
| public static final String DATABASE_NAME = "courses.db"; | ||
|
|
||
| public static final String TABLE_UDACITY = "udacity"; | ||
| public static final String TABLE_COURSEA = "coursea"; | ||
| public static final String TABLE_USERS = "users"; | ||
|
|
||
| // users columns | ||
| public static final String COLUMN_USERNAME = "username"; | ||
| public static final String COLUMN_PASSWORD = "password"; | ||
| public static final String COLUMN_FIRST_NAME = "first_name"; | ||
| public static final String COLUMN_LAST_NAME = "last_name"; | ||
|
|
||
| // udacity and coursea columns | ||
| public static final String COLUMN_ID = "id"; | ||
| public static final String COLUMN_TITLE = "course_title"; | ||
| public static final String COLUMN_DESCRIPTION = "course_description"; | ||
| public static final String COLUMN_IMAGE = "course_image"; | ||
|
|
||
| // udacity columns | ||
| public static final String COLUMN_LEVEL = "course_level"; | ||
|
|
||
| // coursea columns | ||
| public static final String COLUMN_LANGUAGE = "course_language"; | ||
|
|
||
|
|
||
| // create udacity table | ||
| public static final String CREATE_TABLE_UDACITY = | ||
| "CREATE TABLE " + TABLE_UDACITY + " (" + | ||
| COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + | ||
| COLUMN_TITLE + " TEXT, " + | ||
| COLUMN_LEVEL + " TEXT, " + | ||
| COLUMN_DESCRIPTION + " TEXT, " + | ||
| COLUMN_IMAGE + " TEXT);"; | ||
|
|
||
| // create coursea table | ||
| public static final String CREATE_TABLE_COURSEA = | ||
| "CREATE TABLE " + TABLE_COURSEA + " (" + | ||
| COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + | ||
| COLUMN_TITLE + " TEXT, " + | ||
| COLUMN_LANGUAGE + " TEXT, " + | ||
| COLUMN_DESCRIPTION + " TEXT, " + | ||
| COLUMN_IMAGE + " TEXT);"; | ||
|
|
||
|
|
||
| // create users table | ||
| public static final String CREATE_TABLE_USERS = | ||
| "CREATE TABLE " + TABLE_USERS + " (" + | ||
| COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + | ||
| COLUMN_FIRST_NAME + " TEXT, " + | ||
| COLUMN_LAST_NAME + " TEXT, " + | ||
| COLUMN_USERNAME + " TEXT, " + | ||
| COLUMN_PASSWORD + " TEXT);"; | ||
| } |
| @@ -1,30 +1,57 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite; | ||
|
|
||
| import android.content.ContentValues; | ||
| import android.content.Context; | ||
| import android.database.Cursor; | ||
| import android.database.sqlite.SQLiteDatabase; | ||
| import android.database.sqlite.SQLiteOpenHelper; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite.Constants.DbConstants; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class CoursesOpenHelper extends SQLiteOpenHelper { | ||
|
|
||
| public CoursesOpenHelper(Context context) { | ||
| super(context, DbConstants.DATABASE_NAME, null, DbConstants.DATABASE_VERSION); | ||
| } | ||
|
|
||
| @Override | ||
| public void onCreate(SQLiteDatabase db) { | ||
| db.execSQL(DbConstants.CREATE_TABLE_UDACITY); | ||
| db.execSQL(DbConstants.CREATE_TABLE_COURSEA); | ||
| db.execSQL(DbConstants.CREATE_TABLE_USERS); | ||
| } | ||
|
|
||
| public void insertUser(String username, String password, String firstName, String lastName) { | ||
| SQLiteDatabase db = this.getWritableDatabase(); | ||
|
|
||
| ContentValues insertUserValues = new ContentValues(); | ||
| insertUserValues.put(DbConstants.COLUMN_USERNAME, username); | ||
| insertUserValues.put(DbConstants.COLUMN_PASSWORD, password); | ||
| insertUserValues.put(DbConstants.COLUMN_FIRST_NAME, firstName); | ||
| insertUserValues.put(DbConstants.COLUMN_LAST_NAME, lastName); | ||
| db.insert(DbConstants.TABLE_USERS, null, insertUserValues); | ||
|
|
||
| db.close(); | ||
| } | ||
|
|
||
| public String getUser(String username) { | ||
| SQLiteDatabase dbRead = this.getReadableDatabase(); | ||
| Cursor cursor = dbRead.query(DbConstants.TABLE_USERS, new String[]{DbConstants.COLUMN_USERNAME}, "first_name = ?", new String[]{username}, null, null, null); | ||
| int columnUsernameIndex = cursor.getColumnIndex(DbConstants.COLUMN_USERNAME); | ||
| String a = cursor.getString(columnUsernameIndex); | ||
| cursor.close(); | ||
| dbRead.close(); | ||
| return a; | ||
| } | ||
|
|
||
| @Override | ||
| public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
| db.execSQL("DROP TABLE IF EXISTS " + DbConstants.TABLE_UDACITY); | ||
| db.execSQL("DROP TABLE IF EXISTS " + DbConstants.TABLE_COURSEA); | ||
| db.execSQL("DROP TABLE IF EXISTS " + DbConstants.TABLE_USERS); | ||
| onCreate(db); | ||
| } | ||
| } |
| @@ -1,107 +1,112 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.activity; | ||
|
|
||
| import android.content.Intent; | ||
| import android.content.SharedPreferences; | ||
| import android.os.Bundle; | ||
| import android.support.design.widget.Snackbar; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.view.Menu; | ||
| import android.view.MenuItem; | ||
| import android.widget.EditText; | ||
| import android.widget.RelativeLayout; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.PrefsConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.util.VUtils; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import butterknife.OnClick; | ||
|
|
||
| public class LogInActivity extends AppCompatActivity { | ||
|
|
||
| @Bind(R.id.email_input) | ||
| EditText mEmailInput; | ||
|
|
||
| @Bind(R.id.password_input) | ||
| EditText mPasswordInput; | ||
|
|
||
| @Bind(R.id.main_container) | ||
| RelativeLayout mContainer; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_log_in); | ||
| ButterKnife.bind(this); | ||
| } | ||
|
|
||
| @OnClick(R.id.sign_up) | ||
| void signup(){ | ||
| Intent goToSignUp = new Intent(this, SignUpActivity.class); | ||
| startActivity(goToSignUp); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| // Inflate the menu; this adds items to the action bar if it is present. | ||
| getMenuInflater().inflate(R.menu.menu_log_in, menu); | ||
| return true; | ||
| } | ||
|
|
||
| @OnClick(R.id.login_button) | ||
| public void login(){ | ||
| if (isFormedFilled()){ | ||
| saveUserData(VUtils.extractText(mEmailInput), VUtils.extractText(mPasswordInput)); | ||
| showMessage(R.string.login_succes); | ||
| goToMainActivity(); | ||
| } | ||
| else if (isEmailEmpty()){ | ||
| mEmailInput.setError(getString(R.string.email_error)); | ||
| } | ||
| else if (isPasswordEmpty()){ | ||
| mPasswordInput.setError(getString(R.string.password_error)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| // Handle action bar item clicks here. The action bar will | ||
| // automatically handle clicks on the Home/Up button, so long | ||
| // as you specify a parent activity in AndroidManifest.xml. | ||
| int id = item.getItemId(); | ||
|
|
||
| //noinspection SimplifiableIfStatement | ||
| if (id == R.id.action_settings) { | ||
| return true; | ||
| } | ||
|
|
||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
||
| private void showMessage(int stringId) { | ||
| String message = getString(stringId); | ||
| Snackbar.make(mContainer, message, Snackbar.LENGTH_SHORT).show(); | ||
| } | ||
|
|
||
| private boolean isFormedFilled(){ | ||
| return !(isPasswordEmpty() || isEmailEmpty()); | ||
| } | ||
|
|
||
| private boolean isEmailEmpty(){ | ||
| return mEmailInput.getText().toString().isEmpty(); | ||
| } | ||
|
|
||
| private boolean isPasswordEmpty(){ | ||
| return mPasswordInput.getText().toString().isEmpty(); | ||
| } | ||
|
|
||
| private void saveUserData(String username, String password){ | ||
| SharedPreferences sharedPreferences = getSharedPreferences(PrefsConstants.FILE_LOGIN, MODE_PRIVATE); | ||
| sharedPreferences.edit() | ||
| .putString(PrefsConstants.PREF_USERNAME, username) | ||
| .putString(PrefsConstants.PREF_PASSWORD, password) | ||
| .apply(); | ||
| } | ||
|
|
||
| private void goToMainActivity() { | ||
| Intent goToMainActivity = new Intent(this, MainActivity.class); | ||
| startActivity(goToMainActivity); | ||
| finish(); | ||
| } | ||
| } |
| @@ -1,136 +1,149 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.activity; | ||
|
|
||
| import android.content.Intent; | ||
| import android.content.SharedPreferences; | ||
| import android.database.sqlite.SQLiteDatabase; | ||
| import android.os.Bundle; | ||
| import android.support.design.widget.NavigationView; | ||
| import android.support.design.widget.Snackbar; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.support.v4.widget.DrawerLayout; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.support.v7.widget.Toolbar; | ||
| import android.view.Menu; | ||
| import android.view.MenuItem; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.constants.PrefsConstants; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite.CoursesOpenHelper; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment.CourseraFragment; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment.HomeFragment; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment.UdacityFragment; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
|
|
||
| public class MainActivity extends AppCompatActivity { | ||
|
|
||
| @Bind(R.id.app_bar) | ||
| Toolbar mToolbar; | ||
|
|
||
| @Bind(R.id.drawer_layout) | ||
| DrawerLayout mDrawerLayout; | ||
|
|
||
| @Bind(R.id.navigation_view) | ||
| NavigationView mNavigationView; | ||
|
|
||
| @Bind(R.id.username) | ||
| TextView usernameHeader; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
| ButterKnife.bind(this); | ||
| setSupportActionBar(mToolbar); | ||
|
|
||
| CoursesOpenHelper openHelper = new CoursesOpenHelper(getApplicationContext()); | ||
| SQLiteDatabase db = openHelper.getReadableDatabase(); | ||
|
|
||
| if (!isUserDataSaved()) { | ||
| goToLogin(); | ||
| } | ||
|
|
||
| replaceFragment(new HomeFragment()); | ||
|
|
||
| navigationViewOnClick(); | ||
|
|
||
| SharedPreferences sharedPreferences = getSharedPreferences(PrefsConstants.FILE_LOGIN, MODE_PRIVATE); | ||
| String username = sharedPreferences.getString(PrefsConstants.PREF_USERNAME, null); | ||
| usernameHeader.setText(username); | ||
|
|
||
| } | ||
|
|
||
| private void navigationViewOnClick() { | ||
| mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { | ||
| @Override | ||
| public boolean onNavigationItemSelected(MenuItem menuItem) { | ||
| Fragment fragment = null; | ||
| switch (menuItem.getItemId()) { | ||
| case R.id.action_udacity: | ||
| fragment = new UdacityFragment(); | ||
| break; | ||
| case R.id.action_home: | ||
| fragment = new HomeFragment(); | ||
| break; | ||
| case R.id.action_coursera: | ||
| fragment = new CourseraFragment(); | ||
| break; | ||
| } | ||
| replaceFragment(fragment); | ||
| mDrawerLayout.closeDrawers(); | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void replaceFragment(Fragment fragment) { | ||
| FragmentManager fragmentManager = getSupportFragmentManager(); | ||
| fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| // Inflate the menu; this adds items to the action bar if it is present. | ||
| getMenuInflater().inflate(R.menu.menu_main, menu); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| // Handle action bar item clicks here. The action bar will | ||
| // automatically handle clicks on the Home/Up button, so long | ||
| // as you specify a parent activity in AndroidManifest.xml. | ||
| int id = item.getItemId(); | ||
|
|
||
| //noinspection SimplifiableIfStatement | ||
| switch (id) { | ||
| case R.id.action_settings: | ||
| return true; | ||
| case R.id.action_log_out: | ||
| logOut(); | ||
| showMessage(R.string.log_out_message); | ||
| break; | ||
| } | ||
|
|
||
|
|
||
| return super.onOptionsItemSelected(item); | ||
| } | ||
|
|
||
| private void showMessage(int stringId) { | ||
| String message = getString(stringId); | ||
| Snackbar.make(mDrawerLayout, message, Snackbar.LENGTH_SHORT).show(); | ||
| } | ||
|
|
||
| public boolean isUserDataSaved() { | ||
| SharedPreferences sharedPreferences = getSharedPreferences(PrefsConstants.FILE_LOGIN, MODE_PRIVATE); | ||
| return sharedPreferences.contains(PrefsConstants.PREF_USERNAME) | ||
| && sharedPreferences.contains(PrefsConstants.PREF_PASSWORD); | ||
| } | ||
|
|
||
| private void goToLogin() { | ||
| Intent goToLogIn = new Intent(this, LogInActivity.class); | ||
| startActivity(goToLogIn); | ||
| finish(); | ||
| } | ||
|
|
||
| private void logOut() { | ||
| SharedPreferences sharedPreferences = getSharedPreferences(PrefsConstants.FILE_LOGIN, MODE_PRIVATE); | ||
| sharedPreferences.edit() | ||
| .remove(PrefsConstants.PREF_USERNAME) | ||
| .remove(PrefsConstants.PREF_PASSWORD) | ||
| .apply(); | ||
| Intent goToLogIn = new Intent(this, LogInActivity.class); | ||
| startActivity(goToLogIn); | ||
| finish(); | ||
| } | ||
| } |
| @@ -0,0 +1,142 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.activity; | ||
|
|
||
| import android.content.Intent; | ||
| import android.os.Bundle; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.view.Menu; | ||
| import android.view.MenuItem; | ||
| import android.widget.EditText; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite.CoursesOpenHelper; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.util.VUtils; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import butterknife.OnClick; | ||
|
|
||
| public class SignUpActivity extends AppCompatActivity { | ||
|
|
||
| @Bind(R.id.email) | ||
| EditText mEmailInput; | ||
|
|
||
| @Bind(R.id.first_name) | ||
| EditText mFirstNameInput; | ||
|
|
||
| @Bind(R.id.last_name) | ||
| EditText mLastNameInput; | ||
|
|
||
| @Bind({R.id.password, R.id.repeat_password}) | ||
| List<EditText> mPasswordsInput; | ||
|
|
||
| @Bind(R.id.repeat_password) | ||
| EditText mPasswordRepeatInput; | ||
|
|
||
| CoursesOpenHelper openHelper; | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_sign_up); | ||
| ButterKnife.bind(this); | ||
| openHelper = new CoursesOpenHelper(getApplicationContext()); | ||
| } | ||
|
|
||
| @OnClick(R.id.sign_up) | ||
| public void signUp() { | ||
| if (formFilled()){ | ||
| //sign up | ||
| openHelper.insertUser(VUtils.extractText(mEmailInput), | ||
| VUtils.extractText(mPasswordRepeatInput), | ||
| VUtils.extractText(mFirstNameInput), VUtils.extractText(mLastNameInput)); | ||
| goToMain(); | ||
| }else if (isEmailEmpty()){ | ||
| mEmailInput.setError(getString(R.string.email_input_error)); | ||
| }else if (isFirstNameEmpty()){ | ||
| mFirstNameInput.setError(getString(R.string.name_input_error)); | ||
| }else if (isLastNameEmpty()){ | ||
| mLastNameInput.setError("Please enter a ast name"); | ||
| }else if (isPasswordEmpty()){ | ||
| ButterKnife.apply(mPasswordsInput, EMPTY_ERROR); | ||
| }else if (passwordsMatch()){ | ||
| ButterKnife.apply(mPasswordsInput, MATCH_ERROR); | ||
| } | ||
| } | ||
|
|
||
| private void goToMain() { | ||
| Intent goToMain = new Intent(this, MainActivity.class); | ||
| startActivity(goToMain); | ||
| finish(); | ||
| } | ||
|
|
||
| private boolean passwordsMatch() { | ||
| return (mPasswordsInput.get(0).getText().toString().equals(mPasswordsInput.get(1).getText().toString())); | ||
| } | ||
|
|
||
| private boolean formFilled() { | ||
| return !(isNameEmpty() || isEmailEmpty() || isPasswordEmpty()); | ||
| } | ||
|
|
||
| private boolean isNameEmpty() { | ||
| return (isFirstNameEmpty() || isLastNameEmpty()); | ||
| } | ||
|
|
||
| private boolean isEmailEmpty() { | ||
| return (mEmailInput.getText().toString().isEmpty()); | ||
| } | ||
|
|
||
| private boolean isFirstNameEmpty() { | ||
| return (mFirstNameInput.getText().toString().isEmpty()); | ||
| } | ||
|
|
||
| private boolean isLastNameEmpty() { | ||
| return (mLastNameInput.getText().toString().isEmpty()); | ||
| } | ||
|
|
||
| private boolean isPasswordEmpty() { | ||
| for (EditText passwords : mPasswordsInput) { | ||
| if (passwords.getText().toString().isEmpty()) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static final ButterKnife.Action<EditText> EMPTY_ERROR = new ButterKnife.Action<EditText>() { | ||
| @Override | ||
| public void apply(EditText view, int index) { | ||
| view.setError("Please provide a password"); | ||
| } | ||
| }; | ||
|
|
||
| static final ButterKnife.Action<EditText> MATCH_ERROR = new ButterKnife.Action<EditText>() { | ||
| @Override | ||
| public void apply(EditText view, int index) { | ||
| view.setError("Passwords don't match!"); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| @Override | ||
| public boolean onCreateOptionsMenu(Menu menu) { | ||
| // Inflate the menu; this adds items to the action bar if it is present. | ||
| getMenuInflater().inflate(R.menu.menu_sign_up, menu); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onOptionsItemSelected(MenuItem item) { | ||
| // Handle action bar item clicks here. The action bar will | ||
| // automatically handle clicks on the Home/Up button, so long | ||
| // as you specify a parent activity in AndroidManifest.xml. | ||
| int id = item.getItemId(); | ||
|
|
||
| //noinspection SimplifiableIfStatement | ||
| if (id == R.id.action_settings) { | ||
| return true; | ||
| } | ||
|
|
||
| return super.onOptionsItemSelected(item); | ||
| } | ||
| } |
| @@ -1,86 +1,86 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.ImageView; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.CourseraModel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class CourseraRecyclerViewAdapter extends RecyclerView.Adapter<CourseraRecyclerViewAdapter.CourseraViewHolder>{ | ||
|
|
||
| Context mContext; | ||
| LayoutInflater mInflater; | ||
| List<CourseraModel> mCourseList; | ||
|
|
||
| public CourseraRecyclerViewAdapter(Context context, List<CourseraModel> courseList) { | ||
| mContext = context; | ||
| mCourseList = courseList; | ||
| mInflater = LayoutInflater.from(context); | ||
| } | ||
|
|
||
| public void setData(List<CourseraModel> newList){ | ||
| mCourseList = newList; | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public CourseraViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
| View view = mInflater.inflate(R.layout.item_row, parent, false); | ||
| CourseraViewHolder viewHolder = new CourseraViewHolder(view, R.id.title_text, R.id.subtitle_text, R.id.description_text, R.id.image); | ||
| return viewHolder; | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(CourseraViewHolder holder, int position) { | ||
| CourseraModel course = mCourseList.get(position); | ||
| holder.setCourseName(course.getCourseName()); | ||
| holder.setCourseId(course.getCourseId()); | ||
| holder.setCourseDescription(course.getCourseDescription()); | ||
| holder.setCourseImage(course.getCourseImage()); | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return mCourseList.size(); | ||
| } | ||
|
|
||
| public class CourseraViewHolder extends RecyclerView.ViewHolder{ | ||
|
|
||
| TextView mCourseName, mCourseId, mCourseDescription; | ||
| ImageView mCourseImage; | ||
|
|
||
| public CourseraViewHolder(View itemView, int courseNameId, int courseIdId, int courseDescriptionId, int courseImageId) { | ||
| super(itemView); | ||
| mCourseName = (TextView) itemView.findViewById(courseNameId); | ||
| mCourseId = (TextView) itemView.findViewById(courseIdId); | ||
| mCourseDescription = (TextView) itemView.findViewById(courseDescriptionId); | ||
| mCourseImage = (ImageView) itemView.findViewById(courseImageId); | ||
| } | ||
|
|
||
| public void setCourseName(String courseName) { | ||
| this.mCourseName.setText(courseName); | ||
| } | ||
|
|
||
| public void setCourseId(String courseId) { | ||
| this.mCourseId.setText(courseId); | ||
| } | ||
|
|
||
| public void setCourseDescription(String courseDescription){ | ||
| mCourseDescription.setText(courseDescription); | ||
| } | ||
|
|
||
| public void setCourseImage(String courseImage) { | ||
| // Picasso.with(mContext).load(courseImage).placeholder(R.mipmap.ic_launcher).into(mCourseImage); | ||
| } | ||
| } | ||
| } |
| @@ -1,42 +1,42 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.app.FragmentManager; | ||
| import android.support.v4.app.FragmentPagerAdapter; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.ModelFramentPager; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class MyViewPagerAdapter extends FragmentPagerAdapter { | ||
|
|
||
|
|
||
| List<ModelFramentPager> mPagerList = new ArrayList<>(); | ||
| Context mContext; | ||
|
|
||
| public MyViewPagerAdapter(FragmentManager fm, List<ModelFramentPager> pagerList) { | ||
| super(fm); | ||
| this.mPagerList = pagerList; | ||
| this.mContext = mContext; | ||
| } | ||
|
|
||
| @Override | ||
| public Fragment getItem(int position) { | ||
| return mPagerList.get(position).getPager(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getCount() { | ||
| return mPagerList.size(); | ||
| } | ||
|
|
||
| @Override | ||
| public CharSequence getPageTitle(int position) { | ||
| return mPagerList.get(position).getTitle(); | ||
| } | ||
| } |
| @@ -1,93 +1,93 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter; | ||
|
|
||
| import android.content.Context; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.ImageView; | ||
| import android.widget.TextView; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.UdacityModel; | ||
| import com.squareup.picasso.Picasso; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class UdacityRecyclerViewAdapter extends RecyclerView.Adapter<UdacityRecyclerViewAdapter.UdacityViewHolder>{ | ||
|
|
||
| List<UdacityModel> mCourseList; | ||
| Context mContext; | ||
| LayoutInflater mInflater; | ||
|
|
||
|
|
||
|
|
||
| public UdacityRecyclerViewAdapter(Context context, List<UdacityModel> courseList) { | ||
| mContext = context; | ||
| mCourseList = courseList; | ||
| mInflater = LayoutInflater.from(context); | ||
| } | ||
|
|
||
| public void setData(List<UdacityModel> newData){ | ||
| mCourseList = newData; | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
| @Override | ||
| public UdacityViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
| View view = mInflater.inflate(R.layout.item_row ,parent, false); | ||
| UdacityViewHolder viewHolder = new UdacityViewHolder(view, | ||
| R.id.title_text, | ||
| R.id.description_text, | ||
| R.id.subtitle_text, | ||
| R.id.image); | ||
| return viewHolder; | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(UdacityViewHolder holder, int position) { | ||
| UdacityModel course = mCourseList.get(position); | ||
| holder.setCourseName(course.getCourseTitle()); | ||
| holder.setCourseDescription(course.getCourseDescription()); | ||
| holder.setCourseLevel(course.getCourseLevel()); | ||
| holder.setCourseImage(course.getCourseImage()); | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| return mCourseList.size(); | ||
| } | ||
|
|
||
| public class UdacityViewHolder extends RecyclerView.ViewHolder{ | ||
|
|
||
| TextView mCourseName, mCourseDescription, mCourseLevel; | ||
| ImageView mCourseImage; | ||
|
|
||
| public UdacityViewHolder(View itemView, int mCourseNameId, int mCourseDescriptionId, int mCourseLevelId, int mCourseImageId) { | ||
| super(itemView); | ||
| mCourseName = (TextView) itemView.findViewById(mCourseNameId); | ||
| mCourseDescription = (TextView) itemView.findViewById(mCourseDescriptionId); | ||
| mCourseLevel = (TextView) itemView.findViewById(mCourseLevelId); | ||
| mCourseImage = (ImageView) itemView.findViewById(mCourseImageId); | ||
| } | ||
|
|
||
| public void setCourseName(String courseName) { | ||
| mCourseName.setText(courseName); | ||
| } | ||
|
|
||
| public void setCourseDescription(String courseDescription) { | ||
| mCourseDescription.setText(courseDescription); | ||
| } | ||
|
|
||
| public void setCourseLevel(String courseLevel) { | ||
| mCourseLevel.setText(courseLevel); | ||
| } | ||
|
|
||
| public void setCourseImage(String courseImage) { | ||
| Picasso.with(mContext).load(courseImage).into(mCourseImage); | ||
| } | ||
| } | ||
| } |
| @@ -1,104 +1,105 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v7.widget.LinearLayoutManager; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.support.v7.widget.SearchView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.CourseraModel; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.ApiClient; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchCourseraResponse; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter.CourseraRecyclerViewAdapter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import retrofit.Callback; | ||
| import retrofit.RetrofitError; | ||
| import retrofit.client.Response; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class CourseraFragment extends Fragment { | ||
|
|
||
| @Bind(R.id.course_list) | ||
| RecyclerView mRecyclerView; | ||
|
|
||
| @Bind(R.id.search_input) | ||
| SearchView mSearchView; | ||
|
|
||
| CourseraRecyclerViewAdapter mRecyclerViewAdapter; | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| View view = inflater.inflate(R.layout.fragment_list_search, container, false); | ||
| return view; | ||
| } | ||
|
|
||
| @Override | ||
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| super.onViewCreated(view, savedInstanceState); | ||
| ButterKnife.bind(this, view); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onResume() { | ||
| super.onResume(); | ||
| setUpRecyclerView(); | ||
| searchListener(); | ||
| executeWithRetrofit("android"); | ||
| } | ||
|
|
||
| private void searchListener() { | ||
| mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | ||
| @Override | ||
| public boolean onQueryTextSubmit(String query) { | ||
| executeWithRetrofit(query); | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onQueryTextChange(String newText) { | ||
| return false; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void setUpRecyclerView() { | ||
| LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); | ||
| mRecyclerViewAdapter = new CourseraRecyclerViewAdapter(getActivity(), createCourse()); | ||
| mRecyclerView.setLayoutManager(linearLayoutManager); | ||
| mRecyclerView.setAdapter(mRecyclerViewAdapter); | ||
| } | ||
|
|
||
| List<CourseraModel> createCourse(){ | ||
| List<CourseraModel> courseList = new ArrayList<>(); | ||
|
|
||
| return courseList; | ||
| } | ||
|
|
||
| private void executeWithRetrofit(String query) { | ||
| ApiClient.searchCourseraCourse(query, new Callback<SearchCourseraResponse>() { | ||
| @Override | ||
| public void success(SearchCourseraResponse searchCourseraResponse, Response response) { | ||
| List<CourseraModel> newList = searchCourseraResponse.getCourseList(); | ||
| mRecyclerViewAdapter.setData(newList); | ||
| } | ||
|
|
||
| @Override | ||
| public void failure(RetrofitError error) { | ||
|
|
||
| } | ||
| }); | ||
| } | ||
| } |
| @@ -1,70 +1,70 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment; | ||
|
|
||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.support.design.widget.TabLayout; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v4.view.ViewPager; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.ModelFramentPager; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter.MyViewPagerAdapter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class HomeFragment extends Fragment { | ||
|
|
||
| @Bind(R.id.tabs_layout) | ||
| TabLayout mTabLayout; | ||
|
|
||
| @Bind(R.id.pager) | ||
| ViewPager mPager; | ||
|
|
||
| @Override | ||
| public void onCreate(@Nullable Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| View view = inflater.inflate(R.layout.fragment_home, container, false); | ||
| return view; | ||
| } | ||
|
|
||
| @Override | ||
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| super.onViewCreated(view, savedInstanceState); | ||
| ButterKnife.bind(this, view); | ||
| } | ||
|
|
||
| @Override | ||
| public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
| super.onActivityCreated(savedInstanceState); | ||
| setUpTabs(); | ||
| } | ||
|
|
||
| private void setUpTabs() { | ||
| MyViewPagerAdapter viewPagerAdapter = new MyViewPagerAdapter(getChildFragmentManager(), createPager()); | ||
| mPager.setAdapter(viewPagerAdapter); | ||
| mTabLayout.setupWithViewPager(mPager); | ||
| } | ||
|
|
||
| private List<ModelFramentPager> createPager() { | ||
| List<ModelFramentPager> modelFramentPagerList = new ArrayList<>(); | ||
| modelFramentPagerList.add(new ModelFramentPager(new UdacityFragment(), "Udacity")); | ||
| modelFramentPagerList.add(new ModelFramentPager(new CourseraFragment(), "Coursera")); | ||
|
|
||
| return modelFramentPagerList; | ||
| } | ||
| } |
| @@ -1,95 +1,105 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.ui.fragment; | ||
|
|
||
| import android.database.sqlite.SQLiteDatabase; | ||
| import android.os.Bundle; | ||
| import android.support.annotation.Nullable; | ||
| import android.support.v4.app.Fragment; | ||
| import android.support.v7.widget.LinearLayoutManager; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
|
|
||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.R; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.domain.UdacityModel; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.ApiClient; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.io.model.SearchUdacityResponse; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.sqlite.CoursesOpenHelper; | ||
| import com.icaboalo.tabsdrawerretrofitwithbutternife.ui.adapter.UdacityRecyclerViewAdapter; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import butterknife.Bind; | ||
| import butterknife.ButterKnife; | ||
| import retrofit.Callback; | ||
| import retrofit.RetrofitError; | ||
| import retrofit.client.Response; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class UdacityFragment extends Fragment { | ||
|
|
||
| @Bind(R.id.course_list) | ||
| RecyclerView mRecyclerView; | ||
|
|
||
| UdacityRecyclerViewAdapter recyclerViewAdapter; | ||
|
|
||
| @Override | ||
| public void onCreate(@Nullable Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
| View view = inflater.inflate(R.layout.fragment_list, container, false); | ||
| return view; | ||
| } | ||
|
|
||
| @Override | ||
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| super.onViewCreated(view, savedInstanceState); | ||
| ButterKnife.bind(this, view); | ||
| setUpRecyclerView(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onResume() { | ||
| super.onResume(); | ||
| executeWithRetrofit(); | ||
| } | ||
|
|
||
| private void executeWithRetrofit() { | ||
| ApiClient.searchUdacityCourse(new Callback<SearchUdacityResponse>() { | ||
| @Override | ||
| public void success(SearchUdacityResponse searchUdacityResponse, Response response) { | ||
| List<UdacityModel> newCourseList = searchUdacityResponse.getCourses(); | ||
| recyclerViewAdapter.setData(newCourseList); | ||
| } | ||
|
|
||
| @Override | ||
| public void failure(RetrofitError error) { | ||
|
|
||
| } | ||
| }); | ||
| } | ||
|
|
||
| private void setUpRecyclerView() { | ||
| LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); | ||
| recyclerViewAdapter = new UdacityRecyclerViewAdapter(getActivity(), createCourse()); | ||
| mRecyclerView.setLayoutManager(linearLayoutManager); | ||
| mRecyclerView.setAdapter(recyclerViewAdapter); | ||
| } | ||
|
|
||
| public List<UdacityModel> createCourse(){ | ||
| List<UdacityModel> courseList = new ArrayList<>(); | ||
| courseList.add(new UdacityModel()); | ||
|
|
||
| return courseList; | ||
| } | ||
|
|
||
| @Override | ||
| public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
| super.onActivityCreated(savedInstanceState); | ||
| } | ||
|
|
||
| public void createDataBase(){ | ||
| CoursesOpenHelper openHelper = new CoursesOpenHelper(getActivity()); | ||
| SQLiteDatabase db = openHelper.getWritableDatabase(); | ||
|
|
||
| openHelper.onCreate(db); | ||
| // db.insert(DbConstants.TABLE_UDACITY, DbConstants.COLUMN_TITLE, ); | ||
| } | ||
| } |
| @@ -1,13 +1,13 @@ | ||
| package com.icaboalo.tabsdrawerretrofitwithbutternife.util; | ||
|
|
||
| import android.widget.EditText; | ||
|
|
||
| /** | ||
| * Created by icaboalo on 9/26/2015. | ||
| */ | ||
| public class VUtils { | ||
|
|
||
| public static String extractText(EditText editText){ | ||
| return editText.getText().toString(); | ||
| } | ||
| } |
| @@ -1,74 +1,74 @@ | ||
| <RelativeLayout | ||
| android:id="@+id/main_container" | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:padding="16dp" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/email_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_centerVertical="true" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/email_input" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/email" | ||
| android:inputType="textEmailAddress"/> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:id="@+id/password_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_below="@+id/email_container" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
| <EditText | ||
| android:id="@+id/password_input" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginBottom="8dp" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/password" | ||
| android:inputType="textPassword"/> | ||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <Button | ||
| android:id="@+id/login_button" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_below="@+id/password_container" | ||
| android:text="@string/login" | ||
| android:textStyle="bold"/> | ||
|
|
||
| <TextView | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_alignParentBottom="true" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:text="@string/forgot_password" | ||
| android:textAllCaps="true" | ||
| android:textStyle="bold"/> | ||
|
|
||
| <TextView | ||
| android:id="@+id/sign_up" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_alignParentBottom="true" | ||
| android:layout_alignParentEnd="true" | ||
| android:layout_alignParentRight="true" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:text="@string/sign_up" | ||
| android:textAllCaps="true" | ||
| android:textStyle="bold"/> | ||
|
|
||
| </RelativeLayout> | ||
|
|
| @@ -1,36 +1,36 @@ | ||
| <android.support.v4.widget.DrawerLayout | ||
| android:id="@+id/drawer_layout" | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical" | ||
| tools:context=".MainActivity" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical"> | ||
|
|
||
| <include | ||
| android:id="@+id/app_bar" | ||
| layout="@layout/app_bar"/> | ||
|
|
||
| <FrameLayout | ||
| android:id="@+id/container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"/> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <android.support.design.widget.NavigationView | ||
| android:id="@+id/navigation_view" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="match_parent" | ||
| app:menu="@menu/menu_drawer" | ||
| app:headerLayout="@layout/drawer_header" | ||
| android:layout_gravity="start"/> | ||
|
|
||
|
|
||
| </android.support.v4.widget.DrawerLayout> |
| @@ -0,0 +1,117 @@ | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:orientation="vertical" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <include layout="@layout/app_bar" android:id="@+id/app_bar"/> | ||
|
|
||
| <LinearLayout | ||
| android:id="@+id/container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:orientation="vertical" | ||
| android:paddingBottom="@dimen/activity_vertical_margin" | ||
| android:paddingLeft="@dimen/activity_horizontal_margin" | ||
| android:paddingRight="@dimen/activity_horizontal_margin" | ||
| android:paddingTop="@dimen/activity_vertical_margin"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
|
|
||
| <EditText | ||
| android:id="@+id/email" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/email" | ||
| android:inputType="textEmailAddress" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <LinearLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="horizontal" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:layout_width="0dp" | ||
| android:layout_height="match_parent" | ||
| android:layout_weight="0.5"> | ||
|
|
||
|
|
||
| <EditText | ||
| android:id="@+id/first_name" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/first_name" | ||
| android:inputType="textEmailAddress" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:layout_width="0dp" | ||
| android:layout_height="match_parent" | ||
| android:layout_weight="0.5"> | ||
|
|
||
|
|
||
| <EditText | ||
| android:id="@+id/last_name" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/last_name" | ||
| android:inputType="textEmailAddress" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
|
|
||
| <EditText | ||
| android:id="@+id/password" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/password" | ||
| android:inputType="textPassword" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <android.support.design.widget.TextInputLayout | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginBottom="8dp"> | ||
|
|
||
|
|
||
| <EditText | ||
| android:id="@+id/repeat_password" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:fontFamily="sans-serif-condensed" | ||
| android:hint="@string/repeat_password" | ||
| android:inputType="textPassword" /> | ||
|
|
||
| </android.support.design.widget.TextInputLayout> | ||
|
|
||
| <Button | ||
| android:id="@+id/sign_up" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:textStyle="bold" | ||
| android:text="@string/sign_up"/> | ||
|
|
||
| </LinearLayout> | ||
|
|
||
| </LinearLayout> | ||
|
|
| @@ -1,12 +1,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
|
||
| <android.support.v7.widget.Toolbar | ||
|
|
||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:background="@color/colorPrimary" | ||
| app:popupTheme="@style/ThemeOverlay.AppCompat.Light" | ||
| app:theme="@style/CustomToolbar"/> | ||
|
|
| @@ -1,14 +1,28 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="168dp" | ||
| android:orientation="vertical"> | ||
|
|
||
| <ImageView | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:scaleType="centerCrop" | ||
| android:src="@drawable/dev_logo"/> | ||
|
|
||
| <TextView | ||
| android:id="@+id/username" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_alignParentBottom="true" | ||
| android:layout_alignParentLeft="true" | ||
| android:layout_alignParentStart="true" | ||
| android:layout_marginLeft="35dp" | ||
| android:layout_marginStart="35dp" | ||
| android:layout_marginBottom="24dp" | ||
| android:text="username" | ||
| android:textColor="#ffffff" | ||
| android:textSize="24sp"/> | ||
|
|
||
|
|
||
| </RelativeLayout> |
| @@ -1,23 +1,23 @@ | ||
| <?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" | ||
| android:orientation="vertical" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <android.support.design.widget.TabLayout | ||
| android:id="@+id/tabs_layout" | ||
| android:elevation="4dp" | ||
| app:theme="@style/CustomTabLayout" | ||
| android:background="@color/colorPrimary" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"/> | ||
|
|
||
| <android.support.v4.view.ViewPager | ||
| android:id="@+id/pager" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| </android.support.v4.view.ViewPager> | ||
|
|
||
| </LinearLayout> |
| @@ -1,12 +1,13 @@ | ||
| <?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"> | ||
|
|
||
|
|
||
| <android.support.v7.widget.RecyclerView | ||
| android:id="@+id/course_list" | ||
| android:layout_height="match_parent" | ||
| android:layout_width="match_parent"/> | ||
|
|
||
| </LinearLayout> |
| @@ -1,19 +1,19 @@ | ||
| <?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"> | ||
|
|
||
| <android.support.v7.widget.SearchView | ||
| android:id="@+id/search_input" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"> | ||
|
|
||
| </android.support.v7.widget.SearchView> | ||
|
|
||
| <android.support.v7.widget.RecyclerView | ||
| android:id="@+id/course_list" | ||
| android:layout_height="match_parent" | ||
| android:layout_width="match_parent"/> | ||
|
|
||
| </LinearLayout> |