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
29 changes: 28 additions & 1 deletion .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

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.

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

android {
compileSdkVersion 25
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "nyc.c4q.wesniemarcelin.googlenowandroidapp"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -24,15 +24,17 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:25.+'
compile 'com.android.support:recyclerview-v7:25.+'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.marshalchen.ultimaterecyclerview:library:0.7.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.marshalchen.ultimaterecyclerview.itemTouchHelper.*;
import com.marshalchen.ultimaterecyclerview.itemTouchHelper.SimpleItemTouchHelperCallback;

import java.util.ArrayList;

import nyc.c4q.wesniemarcelin.googlenowandroidapp.TodoList.TodoListCarddata;
Expand All @@ -33,9 +38,10 @@ public class MainActivity extends AppCompatActivity {
public static final String BASE_URL = "https://api.vineapp.com/";
public static final String QUOTE_URL = "http://quotes.stormconsultancy.co.uk/";
private static final String TAG = "YOOOOO";
private SwipeRefreshLayout swipeContainer;
private AlertDialog confirmDialogObject;
private static final String MODIFIED_NOTE = "Modified Note";
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String MyPREFERENCES = "MyPrefs";
public static final String NOTE = "noteKey";
private EditText notepad;

Expand All @@ -45,6 +51,7 @@ public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private RecyclerView.Adapter adapter;
private MyAdapter itemTouchHelperAdapter;

ArrayList<CardData> data;

Expand All @@ -54,6 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data = new ArrayList<CardData>();
swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
data.add(new VineCardData(R.drawable.video_of_the_day_image));
data.add(new TodoListCarddata());

Expand All @@ -65,10 +73,37 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
adapter = new MyAdapter(data);
recyclerView.setAdapter(adapter);
notepad = (EditText)findViewById(R.id.edit_text_notepad);
notepad = (EditText) findViewById(R.id.edit_text_notepad);
buildConfirmDialog();

// //Initiate swipe to dismiss call
// ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(MyAdapter);
// ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
// touchHelper.attachToRecyclerView(recyclerView);

//Settings for swipe to refresh
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//quoteRetrofitcall
//vineRetroFitCall
//Service call goes here
// Your code to refresh the list here.
// Make sure you call swipeContainer.setRefreshing(false)
// once the network request has completed successfully.

vineRetrofitCall();
onRefreshQuoteRetrofitCall();
swipeContainer.setRefreshing(false);
}
});
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}


public void quoteretrofitCall() {
Retrofit quoteRetrofit = new Retrofit.Builder()
.baseUrl(QUOTE_URL)
Expand All @@ -81,8 +116,8 @@ public void quoteretrofitCall() {
call.enqueue(new Callback<Quotes>() {
@Override
public void onResponse(Call<Quotes> call, Response<Quotes> response) {
Log.d(TAG, "Success!" + response.body().toString());
Quotes quote = response.body();
Log.d(TAG, "Success!" + response.body().toString());
Quotes quote = response.body();
data.add(new QuoteCardData(quote));
adapter.notifyDataSetChanged();
}
Expand All @@ -94,6 +129,31 @@ public void onFailure(Call<Quotes> call, Throwable t) {
});
}

public void onRefreshQuoteRetrofitCall() {
Retrofit quoteRetrofit = new Retrofit.Builder()
.baseUrl(QUOTE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
QuoteService service = quoteRetrofit.create(QuoteService.class);

Call<Quotes> call = service.listQuotes();
Log.d(TAG, "Succ");
call.enqueue(new Callback<Quotes>() {
@Override
public void onResponse(Call<Quotes> call, Response<Quotes> response) {
Log.d(TAG, "Success!" + response.body().toString());
Quotes quote = response.body();
// data.add(new QuoteCardData(quote));
adapter.notifyDataSetChanged();
}

@Override
public void onFailure(Call<Quotes> call, Throwable t) {
Log.d(TAG, "Error!" + t.getMessage());
}
});
}

public void vineRetrofitCall() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
Expand All @@ -111,9 +171,11 @@ public void onResponse(Call<VineResponse> call, Response<VineResponse> response)
VineCardData obj = (VineCardData) data.get(0);
VineCardData vineAvatar = (VineCardData) data.get(0);
VineCardData vineUsername = (VineCardData) data.get(0);
VineCardData vineUserId = (VineCardData) data.get(0);
obj.setUrl(response.body().getData().getRecords().get(0).videoUrl);
vineAvatar.setAvatarUrl(response.body().getData().getRecords().get(0).avatarUrl);
vineUsername.setUsername(response.body().getData().getRecords().get(0).username);
vineUserId.setUserID(response.body().getData().getRecords().get(0).userId);
adapter.notifyDataSetChanged();

} else {
Expand All @@ -130,7 +192,6 @@ public void onFailure(Call<VineResponse> call, Throwable t) {
}



public void buildConfirmDialog() {
AlertDialog.Builder confirmBuilder = new AlertDialog.Builder(this);
confirmBuilder.setTitle("Are you sure?");
Expand All @@ -145,7 +206,7 @@ public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = sharedpreferences.edit();

editor.putString(NOTE, notepad.getText().toString()).apply();
Toast.makeText(MainActivity.this, sharedpreferences.getString(NOTE,"default"), Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, sharedpreferences.getString(NOTE, "default"), Toast.LENGTH_SHORT).show();

}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import nyc.c4q.wesniemarcelin.googlenowandroidapp.TodoList.TodoListCarddata;
import nyc.c4q.wesniemarcelin.googlenowandroidapp.TodoList.TodoListViewHolder;
Expand All @@ -19,10 +20,10 @@ public class MyAdapter extends RecyclerView.Adapter<CardViewHolder> {

public final int TO_DO_LIST_POSITION = 1;
public final int INSPIRE_CARD_POSITION = 2;
public final int YOUTUBECARD_POSITION = 3;
public final int VINECARD_POSITION = 0;


//List of "objects"
//List of "cards"
public MyAdapter(ArrayList<CardData> cards) {
this.cards = cards;
}
Expand All @@ -38,7 +39,7 @@ public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == INSPIRE_CARD_POSITION) {
return new QuoteViewHolder(parent);
}
if (viewType == YOUTUBECARD_POSITION) {
if (viewType == VINECARD_POSITION) {
return new VineViewHolder(parent);
}
return null;
Expand All @@ -47,30 +48,30 @@ public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//Binds the data to the view
@Override
public void onBindViewHolder(CardViewHolder holder, int position) {
final int viewType = getItemViewType(position);
final int viewType = getItemViewType(position % cards.size());
//noinspection unchecked
//holder.bind(cards.get(position));

if (viewType == TO_DO_LIST_POSITION){
((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get(position));
((TodoListViewHolder) holder).bind((TodoListCarddata) cards.get(position % cards.size()));
}
if(viewType == YOUTUBECARD_POSITION) {
((VineViewHolder) holder).bind((VineCardData) cards.get(position));
if(viewType == VINECARD_POSITION) {
((VineViewHolder) holder).bind((VineCardData) cards.get(position % cards.size()));
}
if(viewType == INSPIRE_CARD_POSITION) {
((QuoteViewHolder) holder).bind((QuoteCardData) cards.get(position));
((QuoteViewHolder) holder).bind((QuoteCardData) cards.get(position % cards.size()));
}
}

@Override
public int getItemViewType(int position) {
if (cards.get(position) instanceof VineCardData) {
return YOUTUBECARD_POSITION;
if ( (position % cards.size() == VINECARD_POSITION)) {
return VINECARD_POSITION;
}
else if (cards.get(position) instanceof TodoListCarddata) {
else if ((position % cards.size() == TO_DO_LIST_POSITION)) {
return TO_DO_LIST_POSITION;
}
else if(cards.get(position) instanceof QuoteCardData){
else if((position % cards.size() == INSPIRE_CARD_POSITION)){
return INSPIRE_CARD_POSITION;
}
else{
Expand All @@ -81,10 +82,24 @@ else if(cards.get(position) instanceof QuoteCardData){
//Counts how many objects that will be in the recycler view
@Override
public int getItemCount() {
return cards.size();
return Integer.MAX_VALUE;
}

//Describes how viewholder should look
// Clean all elements of the recycler
public void clear() {
cards.clear();
notifyDataSetChanged();
}
// Add a list of items
public void addAll(List<CardData> list) {
cards.addAll(list);
notifyDataSetChanged();
}

public void remove(int position) {
cards.remove(position);
notifyItemRemoved(position);
}


}
Loading