Skip to content

Commit

Permalink
Refactoring. Rename Subjects fragment to LastTotal
Browse files Browse the repository at this point in the history
  • Loading branch information
vladholubiev committed Jan 25, 2015
1 parent 5cdc3fe commit 9ffc147
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/Vlad.xml

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

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:name=".App"
android:theme="@style/AppTheme">
<activity
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ua/samosfator/moduleok/DrawableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class DrawableUtils {

private static int[] drawableCircles = {
final private static int[] drawableCircles = {
R.drawable.circle_blue,
R.drawable.circle_brown,
R.drawable.circle_cyan,
Expand All @@ -30,7 +30,7 @@ public static int getDrawableDependsOnScore(int score) {
return R.drawable.circle_5;
} else if (score >= 75 && score < 90) {
return R.drawable.circle_4;
} else if(score >= 60 && score < 75) {
} else if (score >= 60 && score < 75) {
return R.drawable.circle_3;
} else {
return R.drawable.circle_2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;

public class LoadPageAsyncTask extends AsyncTask<Void, Void, String> {
class LoadPageAsyncTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
Document mainPage = Jsoup.parse("<div id=\"content\"></div>");
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ua/samosfator/moduleok/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ua.samosfator.moduleok.event.RefreshEvent;
import ua.samosfator.moduleok.fragment.LoginFragment;
import ua.samosfator.moduleok.fragment.NavigationDrawerFragment;
import ua.samosfator.moduleok.fragment.semesters_subjects_fragment.SubjectsFragment;
import ua.samosfator.moduleok.fragment.last_total_fragment.LastTotalFragment;

public class MainActivity extends ActionBarActivity {
private Toolbar toolbar;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void run() {

private void openSubjectsFragment() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_container, new SubjectsFragment())
.replace(R.id.main_container, new LastTotalFragment())
.commit();
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/ua/samosfator/moduleok/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
public class Preferences {
private static final String PREF_FILE_NAME = "APP_SETTINGS";
private static SharedPreferences sharedPreferences;
private static Context context;

public static void init(Context applicationContext) {
if (sharedPreferences == null) {
context = applicationContext;
sharedPreferences = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
sharedPreferences = applicationContext.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/ua/samosfator/moduleok/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public String getGroupName() {
return getGroup();
}

public Semesters getSemesters() {
return semesters;
}

private String getName() {
if (this.name != null) return this.name;
return getNameParts()[1];
Expand Down Expand Up @@ -77,10 +81,6 @@ private Document getMainPageDocument() {
return Jsoup.parse(mainPageHtml);
}

public Semesters getSemesters() {
return semesters;
}

@Override
public String toString() {
return "Student{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public FlipDirection theOtherDirection() {
}
}

;


/**
* Create a pair of {@link FlipAnimation} that can be used to flip 3D transition from {@code fromView} to {@code toView}. A typical use case is with {@link ViewAnimator} as an out and in transition.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import ua.samosfator.moduleok.R;
import ua.samosfator.moduleok.event.LoginEvent;
import ua.samosfator.moduleok.event.LogoutEvent;
import ua.samosfator.moduleok.fragment.last_total_fragment.LastTotalFragment;
import ua.samosfator.moduleok.fragment.modules_fragment.ModulesFragment;
import ua.samosfator.moduleok.fragment.semesters_subjects_fragment.SubjectsFragment;
import ua.samosfator.moduleok.recyclerview.DrawerSection;
import ua.samosfator.moduleok.recyclerview.RecyclerItemClickListener;

Expand All @@ -34,15 +34,11 @@ public class NavigationDrawerFragment extends Fragment {
private DrawerLayout mDrawerLayout;
public static List<DrawerSection> mSections;

private RecyclerView mRecyclerView;
private SectionAdapter mSectionAdapter;

private boolean mUserSawDrawer;
private boolean mFromSavedInstanceState;

private View containerView;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -69,7 +65,7 @@ private void initSections() {
mSections = new ArrayList<>();

DrawerSection subjectsSection = new DrawerSection(getString(R.string.last_n_total_section), R.drawable.ic_format_list_numbers_grey600_24dp);
subjectsSection.setFragment(new SubjectsFragment());
subjectsSection.setFragment(new LastTotalFragment());
mSections.add(subjectsSection);

DrawerSection modulesSection = new DrawerSection(getString(R.string.modules_section), R.drawable.ic_file_document_box_grey600_24dp);
Expand Down Expand Up @@ -113,15 +109,23 @@ public void addLoginSection() {
}

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
initSectionAdapter();
initRecyclerView(layout);
return layout;
}

mRecyclerView = (RecyclerView) layout.findViewById(R.id.drawer_list);
private void initSectionAdapter() {
mSectionAdapter = new SectionAdapter(getActivity(), mSections);
mRecyclerView.setAdapter(mSectionAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
}

private void initRecyclerView(View layout) {
if (mSectionAdapter == null) initSectionAdapter();
RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.drawer_list);
recyclerView.setAdapter(mSectionAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
getFragmentManager().beginTransaction()
Expand All @@ -130,11 +134,10 @@ public void onItemClick(View view, int position) {
mDrawerLayout.closeDrawers();
}
}));
return layout;
}

public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
containerView = getActivity().findViewById(fragmentId);
View containerView = getActivity().findViewById(R.id.navigation_drawer_fragment);
mDrawerLayout = drawerLayout;

SemesterSpinner.init(mDrawerLayout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public SectionAdapter(Context context, List<DrawerSection> data) {
@Override
public SectionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.fragment_section_item_drawer, parent, false);
SectionViewHolder viewHolder = new SectionViewHolder(view);
return viewHolder;
return new SectionViewHolder(view);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.samosfator.moduleok.fragment.semesters_subjects_fragment;
package ua.samosfator.moduleok.fragment.last_total_fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
Expand Down Expand Up @@ -27,14 +27,12 @@
import ua.samosfator.moduleok.parser.Subject;
import ua.samosfator.moduleok.recyclerview.RecyclerItemClickListener;

public class SubjectsFragment extends Fragment {
public class LastTotalFragment extends Fragment {

private List<Subject> mSubjects = new ArrayList<>();

private RecyclerView mRecyclerView;
private SubjectItemAdapter mSubjectItemAdapter;

public SubjectsFragment() {
public LastTotalFragment() {
// Required empty public constructor
}

Expand All @@ -43,13 +41,13 @@ public void onResume() {
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
Mint.logEvent("view SubjectsFragment", MintLogLevel.Info);
Mint.logEvent("view LastTotalFragment", MintLogLevel.Info);
super.onResume();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_subjects, container, false);
final View rootView = inflater.inflate(R.layout.fragment_last_total, container, false);
initSubjects();
initSectionAdapter();
initRecyclerView(rootView);
Expand All @@ -61,10 +59,10 @@ private void initSectionAdapter() {
}

private void initRecyclerView(View rootView) {
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.subjects_recycler_view);
mRecyclerView.setAdapter(mSubjectItemAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.subjects_recycler_view);
recyclerView.setAdapter(mSubjectItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
setSubjectTotalScore(view, position);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.samosfator.moduleok.fragment.semesters_subjects_fragment;
package ua.samosfator.moduleok.fragment.last_total_fragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -27,8 +27,7 @@ public SubjectItemAdapter(Context context, List<Subject> data) {
@Override
public SubjectItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.fragment_subject_item, parent, false);
SubjectItemViewHolder viewHolder = new SubjectItemViewHolder(view);
return viewHolder;
return new SubjectItemViewHolder(view);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.samosfator.moduleok.fragment.semesters_subjects_fragment;
package ua.samosfator.moduleok.fragment.last_total_fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public class ModuleFragment extends Fragment {

private RecyclerView mRecyclerView;
private ModuleSubjectItemAdapter moduleSubjectItemAdapter;

public ModuleFragment() {
Expand All @@ -35,12 +34,20 @@ public void onResume() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_module, container, false);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.modules_subjects_recycler_view);
initModuleSubjectItemAdapter();
initRecyclerView(rootView);
return rootView;
}

private void initModuleSubjectItemAdapter() {
moduleSubjectItemAdapter = new ModuleSubjectItemAdapter(getActivity(), ModulesFragment.mSubjects, getArguments().getInt("module"));
mRecyclerView.setAdapter(moduleSubjectItemAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}

return rootView;
private void initRecyclerView(View rootView) {
if (moduleSubjectItemAdapter == null) initModuleSubjectItemAdapter();
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.modules_subjects_recycler_view);
recyclerView.setAdapter(moduleSubjectItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}

private void reRenderModuleSubjectsList() {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ua/samosfator/moduleok/parser/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class Module implements Serializable {

Expand All @@ -18,7 +19,7 @@ public class Module implements Serializable {
private Date date;
private int score;

private DateFormat dateFormat = new SimpleDateFormat("dd.MM.yy");
private DateFormat dateFormat = new SimpleDateFormat("dd.MM.yy", Locale.getDefault());

public String getSubjectName() {
return subjectName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public List<Module> getModulesFor(Subject subject) {
public int getModulesCountFor(Subject subject) {
Elements subjectHtmlRow = semesterHtml.select("tr:contains(" + subject.getName() + ")");
Elements cells = Jsoup.parse(subjectHtmlRow.html(), "", Parser.xmlParser()).select("td");
int modulesCount = cutOddCellsFromSubjectRow(cells).size();
@SuppressWarnings("UnnecessaryLocalVariable") int modulesCount = cutOddCellsFromSubjectRow(cells).size();
return modulesCount;
}

Expand Down
Loading

0 comments on commit 9ffc147

Please sign in to comment.