-
Notifications
You must be signed in to change notification settings - Fork 0
Add main functionality #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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(); | ||
| } | ||
| } |
| 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(); | ||
| // 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); | ||
| } | ||
| } | ||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| @Override | ||
| protected Fragment createFragment() { | ||
| return GitPopListFragment.newInstance(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?