-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
238 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# giphy-browser | ||
# GIPHY Browser | ||
|
||
Notes: | ||
|
||
- Models don't have proper getters and setters to save time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
<manifest | ||
xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
package="com.tananaev.giphy"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:usesCleartextTraffic="true" | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
android:theme="@style/AppTheme" | ||
android:name=".MainApplication"> | ||
|
||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.tananaev.giphy; | ||
|
||
import android.app.Application; | ||
|
||
import dagger.hilt.android.HiltAndroidApp; | ||
|
||
@HiltAndroidApp | ||
public class MainApplication extends Application { | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/tananaev/giphy/inject/NetworkModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.tananaev.giphy.inject; | ||
|
||
import com.tananaev.giphy.service.GiphyService; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.components.FragmentComponent; | ||
import retrofit2.Retrofit; | ||
|
||
@Module | ||
@InstallIn(FragmentComponent.class) | ||
public abstract class NetworkModule { | ||
|
||
@Provides | ||
public static GiphyService provideGiphyService() { | ||
return new Retrofit.Builder() | ||
.baseUrl("https://api.giphy.com") | ||
.build() | ||
.create(GiphyService.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tananaev.giphy.model; | ||
|
||
public class Gif { | ||
public Images images; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tananaev.giphy.model; | ||
|
||
public class Image { | ||
public String width; | ||
public String height; | ||
public String url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tananaev.giphy.model; | ||
|
||
public class Images { | ||
public Image preview_gif; | ||
public Image downsized; | ||
public Image original; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tananaev.giphy.model; | ||
|
||
public class Pagination { | ||
public int offset; | ||
public int total_count; | ||
public int count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tananaev.giphy.model; | ||
|
||
import java.util.List; | ||
|
||
public class Response { | ||
public List<Gif> data; | ||
public Pagination pagination; | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/tananaev/giphy/repo/MainRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.tananaev.giphy.repo; | ||
|
||
import com.tananaev.giphy.service.GiphyService; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class MainRepository { | ||
|
||
private GiphyService service; | ||
|
||
@Inject | ||
public MainRepository(GiphyService service) { | ||
this.service = service; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/tananaev/giphy/service/AuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.tananaev.giphy.service; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.HttpUrl; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class AuthInterceptor implements Interceptor { | ||
|
||
private static final String API_KEY = "FdzU6ULmoB0YkKrII9Gzs0HX6fDS4YCo"; | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
|
||
Request original = chain.request(); | ||
HttpUrl originalHttpUrl = original.url(); | ||
|
||
HttpUrl url = originalHttpUrl.newBuilder() | ||
.addQueryParameter("api_key", API_KEY) | ||
.build(); | ||
|
||
Request.Builder requestBuilder = original.newBuilder().url(url); | ||
|
||
Request request = requestBuilder.build(); | ||
return chain.proceed(request); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/tananaev/giphy/service/GiphyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.tananaev.giphy.service; | ||
|
||
import com.tananaev.giphy.model.Response; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
|
||
public interface GiphyService { | ||
@GET("/v1/gifs/trending") | ||
Call<Response> trending(@Query("offset") int offset, @Query("limit") int limit); | ||
} |
44 changes: 32 additions & 12 deletions
44
app/src/main/java/com/tananaev/giphy/ui/main/MainFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,59 @@ | ||
package com.tananaev.giphy.ui.main; | ||
|
||
import androidx.lifecycle.ViewModelProviders; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.lifecycle.ViewModelProvider; | ||
import androidx.lifecycle.ViewModelProviders; | ||
import androidx.paging.PagedListAdapter; | ||
import androidx.recyclerview.widget.GridLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.tananaev.giphy.R; | ||
|
||
import javax.inject.Inject; | ||
|
||
import dagger.hilt.android.AndroidEntryPoint; | ||
|
||
@AndroidEntryPoint | ||
public class MainFragment extends Fragment { | ||
|
||
private MainViewModel mViewModel; | ||
private static final int COLUMNS = 2; | ||
|
||
private MainViewModel viewModel; | ||
private PagedListAdapter adapter; | ||
|
||
@Inject | ||
MainViewModelFactory viewModelFactory; | ||
|
||
public static MainFragment newInstance() { | ||
return new MainFragment(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
public View onCreateView( | ||
@NonNull LayoutInflater inflater, | ||
@Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.main_fragment, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
RecyclerView gridView = view.findViewById(R.id.grid); | ||
gridView.setLayoutManager(new GridLayoutManager(getContext(), COLUMNS)); | ||
|
||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
mViewModel = ViewModelProviders.of(this).get(MainViewModel.class); | ||
// TODO: Use the ViewModel | ||
viewModel = new ViewModelProvider(this, viewModelFactory).get(MainViewModel.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/tananaev/giphy/ui/main/MainViewModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.tananaev.giphy.ui.main; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.lifecycle.ViewModel; | ||
import androidx.lifecycle.ViewModelProvider; | ||
|
||
import com.tananaev.giphy.repo.MainRepository; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class MainViewModelFactory implements ViewModelProvider.Factory { | ||
|
||
private MainRepository repository; | ||
|
||
@Inject | ||
public MainViewModelFactory(MainRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { | ||
return (T) new MainViewModel(repository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
xmlns:app="http:https://schemas.android.com/apk/res-auto" | ||
<FrameLayout | ||
xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
xmlns:tools="http:https://schemas.android.com/tools" | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.main.MainFragment"> | ||
|
||
<TextView | ||
android:id="@+id/message" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="MainFragment" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/grid" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters