Added module detail fragment
This commit is contained in:
@@ -6,7 +6,6 @@ import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
@@ -18,6 +17,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import de.sebse.fuplanner.fragments.LoginFragment;
|
||||
import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
||||
import de.sebse.fuplanner.fragments.ModulesFragment;
|
||||
import de.sebse.fuplanner.fragments.StartupFragment;
|
||||
import de.sebse.fuplanner.services.GoogleAuth.ConnectedListener;
|
||||
@@ -27,7 +27,7 @@ import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.LoginToken;
|
||||
import de.sebse.fuplanner.services.KVV.Modules;
|
||||
import de.sebse.fuplanner.tools.activity.Logger;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -35,13 +35,13 @@ import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener,
|
||||
LoginFragment.OnLoginFragmentInteractionListener,
|
||||
StartupFragment.OnStartupFragmentInteractionListener,
|
||||
ModulesFragment.OnModulesFragmentInteractionListener {
|
||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||
ModDetailFragment.OnModuleDetailFragmentInteractionListener {
|
||||
|
||||
FragmentManager fragmentManager;
|
||||
private GoogleAuth mGoogleAuth;
|
||||
private KVV mKVV;
|
||||
private Logger log = new Logger("MainAct");
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -94,6 +94,7 @@ public class MainActivity extends AppCompatActivity
|
||||
}, new NetworkErrorCallback() {
|
||||
@Override
|
||||
public void onError(NetworkError error) {
|
||||
log.e(error);
|
||||
MainActivity.this.getKVV().endUpdate();
|
||||
changeLoginState(null);
|
||||
}
|
||||
@@ -142,21 +143,30 @@ public class MainActivity extends AppCompatActivity
|
||||
// Handle navigation view item clicks here.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_schedule) {
|
||||
switch (id) {
|
||||
case R.id.nav_modules:
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragcontainer, ModulesFragment.newInstance());
|
||||
fragmentTransaction.commit();
|
||||
break;
|
||||
case R.id.nav_schedule:
|
||||
|
||||
} else if (id == R.id.nav_share) {
|
||||
break;
|
||||
case R.id.nav_share:
|
||||
|
||||
} else if (id == R.id.nav_logout) {
|
||||
this.getKVV().logout();
|
||||
this.getGoogleAuth().getLoginState(new CredentialsListener() {
|
||||
@Override
|
||||
public void onCredentials(Credentials credentials) {
|
||||
if (credentials != null) {
|
||||
MainActivity.this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
||||
break;
|
||||
case R.id.nav_logout:
|
||||
this.getKVV().logout();
|
||||
this.getGoogleAuth().getLoginState(new CredentialsListener() {
|
||||
@Override
|
||||
public void onCredentials(Credentials credentials) {
|
||||
if (credentials != null) {
|
||||
MainActivity.this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
||||
}
|
||||
MainActivity.this.changeLoginState(null);
|
||||
}
|
||||
MainActivity.this.changeLoginState(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
@@ -227,7 +237,7 @@ public class MainActivity extends AppCompatActivity
|
||||
getKVV().getModuleList(new NetworkCallback<Modules>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Modules success) {
|
||||
log.d("Modules.get "+success.size());
|
||||
log.d("Modules.get", success.size());
|
||||
//SubMenu moduleMenu = navigationView.getMenu().findItem(R.id.nav_modules).getSubMenu();
|
||||
int i = 0;
|
||||
for (Modules.Module module: success) {
|
||||
@@ -248,7 +258,7 @@ public class MainActivity extends AppCompatActivity
|
||||
}, new NetworkErrorCallback() {
|
||||
@Override
|
||||
public void onError(NetworkError error) {
|
||||
log.d("Modules.error "+error.toString());
|
||||
log.d("Modules.error", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -269,18 +279,13 @@ public class MainActivity extends AppCompatActivity
|
||||
changeLoginState(credentials);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartupFragmentInteraction(Uri uri) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModulesFragmentInteraction(final int itemPosition) {
|
||||
Log.d("MainAct", "Item clicked "+itemPosition);
|
||||
log.d("Item clicked", itemPosition);
|
||||
getKVV().getModuleList(new NetworkCallback<Modules>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Modules success) {
|
||||
Log.d("MainAct", success.get(itemPosition).title);
|
||||
log.d(success.get(itemPosition).title);
|
||||
}
|
||||
}, new NetworkErrorCallback() {
|
||||
@Override
|
||||
@@ -288,5 +293,14 @@ public class MainActivity extends AppCompatActivity
|
||||
// TODO
|
||||
}
|
||||
});
|
||||
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragcontainer, ModDetailFragment.newInstance(itemPosition));
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModuleDetailFragmentInteraction(Uri uri) {
|
||||
log.d("Cooles ding");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import de.sebse.fuplanner.services.GoogleAuth.Credentials;
|
||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.LoginToken;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -36,6 +37,7 @@ public class LoginFragment extends Fragment {
|
||||
// TODO: Rename and change types of parameters
|
||||
|
||||
private OnLoginFragmentInteractionListener mListener;
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public LoginFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -83,7 +85,7 @@ public class LoginFragment extends Fragment {
|
||||
if (input_usr != null) {
|
||||
if (input_pwd != null) {
|
||||
if (LoginFragment.this.getActivity() == null) {
|
||||
Log.e("KVVLogin", "Login fragment has no activity!");
|
||||
log.e("Login fragment has no activity!");
|
||||
return;
|
||||
}
|
||||
final String username = input_usr.getText().toString();
|
||||
@@ -94,7 +96,7 @@ public class LoginFragment extends Fragment {
|
||||
@Override
|
||||
public void onResponse(@NonNull LoginToken success) {
|
||||
progressDialog.dismiss();
|
||||
Log.d("KVVLogin", success.toString());
|
||||
log.d("success", success.toString());
|
||||
gauth.setLoginState(username, password);
|
||||
if (LoginFragment.this.mListener != null) {
|
||||
Credentials cred = new Credentials(username, password);
|
||||
@@ -105,7 +107,7 @@ public class LoginFragment extends Fragment {
|
||||
@Override
|
||||
public void onError(NetworkError error) {
|
||||
progressDialog.dismiss();
|
||||
Log.e("KVVLoginError", error.getCode()+"");
|
||||
log.e("error", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.sebse.fuplanner.fragments;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -19,12 +20,6 @@ import de.sebse.fuplanner.R;
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class StartupFragment extends Fragment {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
|
||||
private OnStartupFragmentInteractionListener mListener;
|
||||
|
||||
public StartupFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -36,7 +31,6 @@ public class StartupFragment extends Fragment {
|
||||
*
|
||||
* @return A new instance of fragment StartupFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static StartupFragment newInstance() {
|
||||
StartupFragment fragment = new StartupFragment();
|
||||
Bundle args = new Bundle();
|
||||
@@ -50,42 +44,9 @@ public class StartupFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View v = inflater.inflate(R.layout.fragment_startup, container, false);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnStartupFragmentInteractionListener) {
|
||||
mListener = (OnStartupFragmentInteractionListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnStartupFragmentInteractionListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
* to the activity and potentially other fragments contained in that
|
||||
* activity.
|
||||
* <p>
|
||||
* See the Android Training lesson <a href=
|
||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
||||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnStartupFragmentInteractionListener {
|
||||
// TODO: Update argument type and name
|
||||
void onStartupFragmentInteraction(Uri uri);
|
||||
return inflater.inflate(R.layout.fragment_startup, container, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
class ModDetailAdapter extends FragmentPagerAdapter {
|
||||
public ModDetailAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
|
||||
// Returns total number of pages
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Returns the fragment to display for that page
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
case 0: // Fragment # 0 - This will show FirstFragment
|
||||
return ModDetailOverviewFragment.newInstance("1", "Page # 1");
|
||||
case 1: // Fragment # 0 - This will show FirstFragment different title
|
||||
return ModDetailAnnounceFragment.newInstance("2", "Page # 2");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the page title for the top indicator
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return "Page " + position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import de.sebse.fuplanner.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link ModDetailAnnounceFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ModDetailAnnounceFragment extends Fragment {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
|
||||
public ModDetailAnnounceFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ModDetailAnnounceFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ModDetailAnnounceFragment newInstance(String param1, String param2) {
|
||||
ModDetailAnnounceFragment fragment = new ModDetailAnnounceFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_mod_detail_announce, container, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
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 de.sebse.fuplanner.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link OnModuleDetailFragmentInteractionListener} interface
|
||||
* to handle interaction events.
|
||||
* Use the {@link ModDetailFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ModDetailFragment extends Fragment {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_POSITION = "itemPosition";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private int mItemPos;
|
||||
|
||||
private OnModuleDetailFragmentInteractionListener mListener;
|
||||
private ModDetailAdapter adapterViewPager;
|
||||
|
||||
public ModDetailFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param itemPosition Item position in module list.
|
||||
* @return A new instance of fragment ModDetailFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static Fragment newInstance(int itemPosition) {
|
||||
ModDetailFragment fragment = new ModDetailFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_POSITION, itemPosition);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mItemPos = getArguments().getInt(ARG_POSITION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View v = inflater.inflate(R.layout.fragment_mod_detail, container, false);
|
||||
|
||||
ViewPager vpPager = (ViewPager) v.findViewById(R.id.vpPager);
|
||||
adapterViewPager = new ModDetailAdapter(getFragmentManager());
|
||||
vpPager.setAdapter(adapterViewPager);
|
||||
return v;
|
||||
}
|
||||
|
||||
// TODO: Rename method, update argument and hook method into UI event
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
mListener.onModuleDetailFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnModuleDetailFragmentInteractionListener) {
|
||||
mListener = (OnModuleDetailFragmentInteractionListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnModuleDetailFragmentInteractionListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
* to the activity and potentially other fragments contained in that
|
||||
* activity.
|
||||
* <p>
|
||||
* See the Android Training lesson <a href=
|
||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
||||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnModuleDetailFragmentInteractionListener {
|
||||
// TODO: Update argument type and name
|
||||
void onModuleDetailFragmentInteraction(Uri uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import de.sebse.fuplanner.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link ModDetailOverviewFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ModDetailOverviewFragment extends Fragment {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
|
||||
public ModDetailOverviewFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ModDetailOverviewFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ModDetailOverviewFragment newInstance(String param1, String param2) {
|
||||
ModDetailOverviewFragment fragment = new ModDetailOverviewFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_mod_detail_overview, container, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,13 +4,11 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.NetworkResponse;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.VolleyLog;
|
||||
import com.android.volley.toolbox.HttpHeaderParser;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package de.sebse.fuplanner.tools.activity;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 19.04.18.
|
||||
*/
|
||||
|
||||
public class Logger {
|
||||
private final String tag;
|
||||
|
||||
public Logger(String tag) {
|
||||
super();
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public void d(String text) {
|
||||
Log.d(tag, text);
|
||||
}
|
||||
|
||||
public void d(boolean text) {
|
||||
Log.d(tag, String.valueOf(text));
|
||||
}
|
||||
|
||||
public void d(int text) {
|
||||
Log.d(tag, String.valueOf(text));
|
||||
}
|
||||
|
||||
public void e(String text) {
|
||||
Log.e(tag, text);
|
||||
}
|
||||
|
||||
public void e(boolean text) {
|
||||
Log.e(tag, String.valueOf(text));
|
||||
}
|
||||
|
||||
public void e(int text) {
|
||||
Log.e(tag, String.valueOf(text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package de.sebse.fuplanner.tools.logging;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class Logger {
|
||||
private final String tag;
|
||||
|
||||
public Logger(Object object) {
|
||||
this.tag = object.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public void d(Object... msg) {
|
||||
Log.d(tag, concat(msg));
|
||||
}
|
||||
|
||||
public void e(Object... msg) {
|
||||
Log.e(tag, concat(msg));
|
||||
}
|
||||
|
||||
private String concat(Object[] msg) {
|
||||
StringBuilder string = new StringBuilder();
|
||||
for (Object arg: msg)
|
||||
if (arg != null)
|
||||
string.append(arg.toString()).append(" ");
|
||||
else
|
||||
string.append("null ");
|
||||
return string.toString();
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class BetterHurlStack extends HurlStack {
|
||||
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
|
||||
throws IOException, AuthFailureError {
|
||||
String url = request.getUrl();
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.putAll(request.getHeaders());
|
||||
map.putAll(additionalHeaders);
|
||||
if (mUrlRewriter != null) {
|
||||
|
||||
@@ -5,9 +5,11 @@ import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.NetworkResponse;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.TimeoutError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
|
||||
@@ -16,6 +18,8 @@ import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 24.10.17.
|
||||
*/
|
||||
@@ -23,6 +27,7 @@ import java.util.Map;
|
||||
public class HTTPService {
|
||||
protected RequestQueue requestQueue;
|
||||
private boolean followRedirects;
|
||||
protected Logger log = new Logger(this);
|
||||
|
||||
public HTTPService(Context context) {
|
||||
this(context, false);
|
||||
@@ -38,10 +43,17 @@ public class HTTPService {
|
||||
@Override
|
||||
public void deliverError(VolleyError error) {
|
||||
if (error == null) {
|
||||
super.deliverError(null);
|
||||
super.deliverError(new VolleyError(new NetworkResponse(500, null, null, true, 0)));
|
||||
} else if (error.networkResponse == null) {
|
||||
int statusCode;
|
||||
if (error instanceof TimeoutError)
|
||||
statusCode = 408;
|
||||
else
|
||||
statusCode = 500;
|
||||
super.deliverError(new VolleyError(new NetworkResponse(statusCode, null, null, true, error.getNetworkTimeMs())));
|
||||
} else {
|
||||
final int status = error.networkResponse.statusCode;
|
||||
if (status == 302 && !followRedirects) {
|
||||
if (status == 302) {
|
||||
super.deliverResponse(new Result(null, error.networkResponse.headers));
|
||||
} else {
|
||||
super.deliverError(error);
|
||||
@@ -87,7 +99,7 @@ public class HTTPService {
|
||||
sb.append('&');
|
||||
}
|
||||
try {
|
||||
Log.e("Superissimo", e.getKey()+"|||"+e.getValue());
|
||||
//Log.e("Superissimo", e.getKey()+"|||"+e.getValue());
|
||||
sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(e.getValue(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException ignored) {
|
||||
}
|
||||
@@ -102,11 +114,22 @@ public class HTTPService {
|
||||
|
||||
@Override
|
||||
public void deliverError(VolleyError error) {
|
||||
final int status = error.networkResponse.statusCode;
|
||||
if (status == 302) {
|
||||
super.deliverResponse(new Result(null, error.networkResponse.headers));
|
||||
if (error == null) {
|
||||
super.deliverError(new VolleyError(new NetworkResponse(500, null, null, true, 0)));
|
||||
} else if (error.networkResponse == null) {
|
||||
int statusCode;
|
||||
if (error instanceof TimeoutError)
|
||||
statusCode = 408;
|
||||
else
|
||||
statusCode = 500;
|
||||
super.deliverError(new VolleyError(new NetworkResponse(statusCode, null, null, true, error.getNetworkTimeMs())));
|
||||
} else {
|
||||
super.deliverError(error);
|
||||
final int status = error.networkResponse.statusCode;
|
||||
if (status == 302) {
|
||||
super.deliverResponse(new Result(null, error.networkResponse.headers));
|
||||
} else {
|
||||
super.deliverError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +153,7 @@ public class HTTPService {
|
||||
requestQueue.add(request);
|
||||
}
|
||||
|
||||
public static void largeLog(String tag, String content) {
|
||||
private static void largeLog(String tag, String content) {
|
||||
if (content==null) {
|
||||
Log.d(tag, "null");
|
||||
} else if (content.length() > 4000) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.sebse.fuplanner.tools.network;
|
||||
|
||||
import com.android.volley.DefaultRetryPolicy;
|
||||
import com.android.volley.NetworkResponse;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
@@ -12,12 +13,17 @@ import java.io.UnsupportedEncodingException;
|
||||
*/
|
||||
|
||||
public class HttpRequest extends Request<Result> {
|
||||
private static final int MY_SOCKET_TIMEOUT_MS = 15000;
|
||||
private final Response.Listener<Result> mListener;
|
||||
|
||||
public HttpRequest(int method, String url, Response.Listener<Result> listener,
|
||||
Response.ErrorListener errorListener) {
|
||||
super(method, url, errorListener);
|
||||
mListener = listener;
|
||||
this.setRetryPolicy(new DefaultRetryPolicy(
|
||||
MY_SOCKET_TIMEOUT_MS,
|
||||
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
|
||||
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
21
app/src/main/res/layout/fragment_mod_detail.xml
Normal file
21
app/src/main/res/layout/fragment_mod_detail.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/vpPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v4.view.PagerTabStrip
|
||||
android:id="@+id/pager_header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingTop="4dp" />
|
||||
|
||||
</android.support.v4.view.ViewPager>
|
||||
</LinearLayout>
|
||||
14
app/src/main/res/layout/fragment_mod_detail_announce.xml
Normal file
14
app/src/main/res/layout/fragment_mod_detail_announce.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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"
|
||||
tools:context=".fragments.moddetails.ModDetailAnnounceFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Announcement fragment" />
|
||||
|
||||
</FrameLayout>
|
||||
14
app/src/main/res/layout/fragment_mod_detail_overview.xml
Normal file
14
app/src/main/res/layout/fragment_mod_detail_overview.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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"
|
||||
tools:context=".fragments.moddetails.ModDetailOverviewFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Overview Fragment" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -8,6 +8,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
|
||||
tools:context="de.sebse.fuplanner.fragments.ModulesFragment"
|
||||
tools:listitem="@layout/fragment_modules" />
|
||||
|
||||
Reference in New Issue
Block a user