Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

19 changes: 15 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
compileSdkVersion 26
compileSdkVersion 27
defaultConfig {
applicationId "com.blink22.android.gitpop"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -19,10 +20,20 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blink22.android.gitpop">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SingleFragmentActivity">
<activity android:name=".GitPopListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".GitPopPageActivity">
</activity>

</application>

</manifest>
41 changes: 41 additions & 0 deletions app/src/main/java/com/blink22/android/gitpop/GitPopAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.blink22.android.gitpop;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

/**
* Created by ahmedghazy on 7/17/18.
*/

public class GitPopAdapter extends RecyclerView.Adapter<GitPopHolder> {
Context mContext;
List<Repo> mRepos;

public GitPopAdapter(Context context) {
mContext = context;
}

@Override
public GitPopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mContext);
return new GitPopHolder(inflater, parent, mContext);
}

public void setRepos(List<Repo> repos) {
mRepos = repos;
}

@Override
public void onBindViewHolder(GitPopHolder holder, int position) {
holder.bind(mRepos.get(position));
}

@Override
public int getItemCount() {
return mRepos.size();
}
}
68 changes: 68 additions & 0 deletions app/src/main/java/com/blink22/android/gitpop/GitPopFetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.blink22.android.gitpop;

import android.util.Log;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Created by ahmedghazy on 7/18/18.
*/

public class GitPopFetcher {
private static final String TAG = "GitPopFetcher";

Retrofit mRetrofit;
GitPopService mGitPopService;
public GitPopFetcher() {
// HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AFGhazy IMHO It will be better to do without commented lines of code. What do you think?

// logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// httpClient.addInterceptor(logging);

mRetrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(GsonConverterFactory.create())
// .client(httpClient.build())
.build();
mGitPopService = mRetrofit.create(GitPopService.class);

}

public void getReposForUser(String user, Callback<List<Repo>> callback) {
mGitPopService.listReposForUser(user).enqueue(callback);
}

public void getMostPopularReposForTheLastWeek(Callback<List<Repo>> callback) {
// Calendar cal = Calendar.getInstance();
// cal.setTime(new Date());
// cal.add(Calendar.DATE, -7);
// Date dateBefore7Days = cal.getTime();
// SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
// Log.i(TAG, dt1.format(dateBefore7Days));
Map<String, String> params = new HashMap<String, String>();
// params.put("sort", "stars");
// params.put("order", "desc");
// params.put("q", "created:>2018-07-01");
mGitPopService.listReposForMostPopularSince(params).enqueue(callback);
}

public void getContributers(String repo, Callback<List<User>> callback) {
mGitPopService.listContributersFor(repo).enqueue(callback);
}
}
53 changes: 53 additions & 0 deletions app/src/main/java/com/blink22/android/gitpop/GitPopHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.blink22.android.gitpop;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
* Created by ahmedghazy on 7/17/18.
*/

public class GitPopHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
@BindView(R.id.list_item_title) TextView mTitle;
@BindView(R.id.list_item_technology) TextView mLanguage;
Context mContext;

private static final Map<String, Integer> colors = new HashMap<String, Integer>(){{
put("Java", Color.BLUE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AFGhazy I suggest using constants, in general, rather than static strings to improve readability and maintainability. What do you think?

put("Ruby", Color.RED);
put("JavaScript", Color.YELLOW);
}};

public GitPopHolder(LayoutInflater inflater, ViewGroup parent, Context context) {
super(inflater.inflate(R.layout.list_item_git_pop, parent, false));
itemView.setOnClickListener(this);
ButterKnife.bind(this, itemView);
mContext = context;
}

public void bind(Repo repo) {
mTitle.setText(repo.getFull_name());
mLanguage.setText(repo.getLanguage());
if(colors.get(repo.getLanguage()) != null)
Log.i("GitPopHolder", colors.get(repo.getLanguage()).toString());
mLanguage.setTextColor(colors.get(repo.getLanguage()) != null ? colors.get(repo.getLanguage()) : Color.BLACK);
}

@Override
public void onClick(View view) {
mContext.startActivity(GitPopPageActivity.newIntent(mContext, mTitle.getText().toString()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.blink22.android.gitpop;

import android.support.v4.app.Fragment;

/**
* Created by ahmedghazy on 7/17/18.
*/

public class GitPopListActivity extends SingleFragmentActivity {
Copy link

@IslamSalah IslamSalah Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AFGhazy I'm not sure but this class seems to be never called in the code base. Kindly correct me if I missed something.

UPD
Sorry I missed that it's the launcher

@Override
protected Fragment createFragment() {
return GitPopListFragment.newInstance();
}
}
Loading